Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Oct 30, 2024
0 parents commit 0b07b09
Show file tree
Hide file tree
Showing 31 changed files with 963 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: rake

on:
push:
branches: [ master, main ]
tags: [ v* ]
pull_request:
workflow_dispatch:

jobs:
rake:
uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: release

on:
workflow_dispatch:
inputs:
next_version:
description: |
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
required: true
default: 'skip'
push:
tags: [ v* ]

jobs:
release:
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
with:
next_version: ${{ github.event.inputs.next_version }}
secrets:
rubygems-api-key: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }}
pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
34 changes: 34 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 2.7

Gemspec/DevelopmentDependencies:
Enabled: false

Gemspec/RequireMFA:
Enabled: false

Metrics/BlockLength:
AllowedMethods:
- describe

Style/Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
51 changes: 51 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-08-27 09:46:41 UTC using RuboCop version 1.65.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'lib/genericode/code_list.rb'

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 182

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 34

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 220

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 92

# Offense count: 10
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 86

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 92

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 121
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in reqif.gemspec
gemspec

gem "nokogiri"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
gem "rubocop-performance"
gem "xml-c14n"
171 changes: 171 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
= ALI

image:https://img.shields.io/gem/v/ali.svg["Gem Version", link="https://rubygems.org/gems/ali"]
image:https://github.com/lutaml/ali/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/ali/actions?workflow=rake"]
image:https://codeclimate.com/github/lutaml/ali/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/lutaml/ali"]

== Purpose

This Ruby gem implements the
https://www.niso.org/schemas/ali/1.0[NISO Access and License Indicators (ALI) Schemas].

Specification:

* https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021]

It can be used to parse and generate ALI XML and JSON files.

NOTE: NISO ALI is used by the NISO JATS standard to indicate the access and
license information of a document.

NOTE: The `ali` gem is used by the `niso-jats` gem to parse and generate ALI
files in the context of JATS documents.


== Installation

To install the `ali` gem, use one of the following methods.

Add this line to your application's Gemfile:

[source,ruby]
----
gem 'ali'
----

Then execute:

[source,sh]
----
$ bundle install
----

Or install it directly using:

[source,sh]
----
$ gem install ali
----

After installation, you can start using the ali gem in your Ruby projects
or via the command-line interface.



== API

=== General

The gem provides the following classes:

* `Ali::FreeToRead`:: Represents the `free_to_read` element.
* `Ali::License`:: Represents the `license` element.
* `Ali::Container`:: Represents the root element of the ALI document. (Applies to JSON only)

=== Differences between XML and JSON usage of ALI

Notice that the XML usage and JSON usage of ALI differs:

XML:: The `free_to_read` and `license` elements are directly incorporated into
an XML document that is defined by an external schema. ALI itself does not
define any root container.

JSON-LD:: The `free_to_read` and `license` elements are contained in a JSON
object under the JSON-LD context defined in ALI. In the `ali` gem, the
`Ali::Container` class is used to represent the root element of the ALI
document.

=== Usage with XML

When parsing ALI in XML, you need to incorporate the ALI element
classes in the context of the XML document.

[example]
====
Usage of ALI elements in XML is not contained in a particular element.
[source,xml]
----
<external-document ...>
<!-- other elements -->
<free_to_read xmlns="http://www.niso.org/schemas/ali/1.0/"
start_date="2014-01-01" end_date="2014-12-31"/>
<license_ref xmlns="http://www.niso.org/schemas/ali/1.0/"
start_date="2015-02-03">
http://www.examplesite.org/open_license.html
</license_ref>
<!-- other elements -->
</external-document>
----
====

.Usage with XML
[source,ruby]
----
> require 'ali'
> xml = '<free_to_read xmlns="http://www.niso.org/schemas/ali/1.0/" start_date="2014-01-01"
end_date="2014-12-31"/>'
> free_to_read = Ali::FreeToRead.from_xml(xml)
> free_to_read.start_date
# => "2014-01-01"
> free_to_read.end_date
# => "2014-12-31"
----

=== Usage with JSON

When parsing ALI in JSON, you need to use the `Ali::Container` class to
parse the root element of the ALI object.

[example]
====
Usage of ALI in JSON-LD is contained in an JSON object.
[source,json]
----
{
"@context": "http://www.niso.org/schemas/ali/1.0.1/jsonld.json",
"free_to_read": {
"start_date": "2014-01-01",
"end_date": "2014-12-31"
},
"license_ref": {
"start_date": "2014-04-04",
"uri": "http://creativecommons.org/licenses/by/3.0/"
}
}
----
====

.Usage with JSON
[source,ruby]
----
> require 'ali'
> json = '{"free_to_read": {"start_date": "2014-01-01", "end_date": "2014-12-31"}}'
> container = Ali::Container.from_json(json)
> free_to_read = container.free_to_read
> free_to_read.start_date
# => "2014-01-01"
> free_to_read.end_date
# => "2014-12-31"
----


== Tests

The `spec/fixtures` folder tests the library against known examples of ALI.

Including:

`spec/fixtures/json`:: JSON examples from
https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021], A.4.

`spec/fixtures/xml`:: XML examples from
https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021], A.1.


== License

Copyright Ribose.

BSD-3 license.
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[spec rubocop]
35 changes: 35 additions & 0 deletions ali.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require_relative "lib/ali/version"

Gem::Specification.new do |spec|
spec.name = "ali"
spec.version = Ali::VERSION
spec.authors = ["Ribose Inc."]
spec.email = ["[email protected]'"]

spec.summary = "NISO Access and License Indicators (ALI) Schemas library"
spec.description = "A Ruby library for parsing and generating NISO Access and License Indicators (ALI) Schemas data"
spec.homepage = "https://github.com/lutaml/ali"
spec.license = "MIT"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["changelog_uri"] = "https://github.com/lutaml/ali/releases"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem
# that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`
.split("\x0")
.reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 3.0.0"

spec.add_dependency "lutaml-model"
end
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "ali"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
Loading

0 comments on commit 0b07b09

Please sign in to comment.