ali 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87c6eabd67795103f67548a9d919c6d32f18f33cff4031732af54d5d476793e6
4
+ data.tar.gz: '0813d3011868515c36890d1ff33252b7f085b67556865ca83d91da4dddab19b5'
5
+ SHA512:
6
+ metadata.gz: 5e2a51ca271a68b902b7271b136112d5044f54a1b4b94ad7880818c7587aedc4d9745a88d61b991c38a5748acf40f1c227f0c725c175e2bf0b8afefd46f4eb63
7
+ data.tar.gz: 4b3d02847bd0d2afab3a9d44af3c25f02a6a63a43493f7c722db9ca6304990923efb0ec8e1a6afce38a8d0e020078d743827ae04442aa747724c4748dcde5e30
@@ -0,0 +1,12 @@
1
+ name: rake
2
+
3
+ on:
4
+ push:
5
+ branches: [ master, main ]
6
+ tags: [ v* ]
7
+ pull_request:
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ rake:
12
+ uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
@@ -0,0 +1,22 @@
1
+ name: release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ next_version:
7
+ description: |
8
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
9
+ required: true
10
+ default: 'skip'
11
+ push:
12
+ tags: [ v* ]
13
+
14
+ jobs:
15
+ release:
16
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
17
+ with:
18
+ next_version: ${{ github.event.inputs.next_version }}
19
+ secrets:
20
+ rubygems-api-key: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }}
21
+ pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
22
+
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+ SuggestExtensions: false
6
+ TargetRubyVersion: 2.7
7
+
8
+ Gemspec/DevelopmentDependencies:
9
+ Enabled: false
10
+
11
+ Gemspec/RequireMFA:
12
+ Enabled: false
13
+
14
+ Metrics/BlockLength:
15
+ AllowedMethods:
16
+ - describe
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Style/StringLiterals:
22
+ EnforcedStyle: double_quotes
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ EnforcedStyle: double_quotes
26
+
27
+ Style/TrailingCommaInArguments:
28
+ EnforcedStyleForMultiline: consistent_comma
29
+
30
+ Style/TrailingCommaInArrayLiteral:
31
+ EnforcedStyleForMultiline: consistent_comma
32
+
33
+ Style/TrailingCommaInHashLiteral:
34
+ EnforcedStyleForMultiline: consistent_comma
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-10-30 08:03:48 UTC using RuboCop version 1.67.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'ali.gemspec'
15
+
16
+ # Offense count: 5
17
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
18
+ # AllowedMethods: refine
19
+ Metrics/BlockLength:
20
+ Max: 81
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in reqif.gemspec
6
+ gemspec
7
+
8
+ gem "nokogiri"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
12
+ gem "rubocop-performance"
13
+ gem "xml-c14n"
data/README.adoc ADDED
@@ -0,0 +1,171 @@
1
+ = ALI
2
+
3
+ image:https://img.shields.io/gem/v/ali.svg["Gem Version", link="https://rubygems.org/gems/ali"]
4
+ image:https://github.com/lutaml/ali/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/ali/actions?workflow=rake"]
5
+ image:https://codeclimate.com/github/lutaml/ali/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/lutaml/ali"]
6
+
7
+ == Purpose
8
+
9
+ This Ruby gem implements the
10
+ https://www.niso.org/schemas/ali/1.0[NISO Access and License Indicators (ALI) Schemas].
11
+
12
+ Specification:
13
+
14
+ * https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021]
15
+
16
+ It can be used to parse and generate ALI XML and JSON files.
17
+
18
+ NOTE: NISO ALI is used by the NISO JATS standard to indicate the access and
19
+ license information of a document.
20
+
21
+ NOTE: The `ali` gem is used by the `niso-jats` gem to parse and generate ALI
22
+ files in the context of JATS documents.
23
+
24
+
25
+ == Installation
26
+
27
+ To install the `ali` gem, use one of the following methods.
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ [source,ruby]
32
+ ----
33
+ gem 'ali'
34
+ ----
35
+
36
+ Then execute:
37
+
38
+ [source,sh]
39
+ ----
40
+ $ bundle install
41
+ ----
42
+
43
+ Or install it directly using:
44
+
45
+ [source,sh]
46
+ ----
47
+ $ gem install ali
48
+ ----
49
+
50
+ After installation, you can start using the ali gem in your Ruby projects
51
+ or via the command-line interface.
52
+
53
+
54
+
55
+ == API
56
+
57
+ === General
58
+
59
+ The gem provides the following classes:
60
+
61
+ * `Ali::FreeToRead`:: Represents the `free_to_read` element.
62
+ * `Ali::License`:: Represents the `license` element.
63
+ * `Ali::Container`:: Represents the root element of the ALI document. (Applies to JSON only)
64
+
65
+ === Differences between XML and JSON usage of ALI
66
+
67
+ Notice that the XML usage and JSON usage of ALI differs:
68
+
69
+ XML:: The `free_to_read` and `license` elements are directly incorporated into
70
+ an XML document that is defined by an external schema. ALI itself does not
71
+ define any root container.
72
+
73
+ JSON-LD:: The `free_to_read` and `license` elements are contained in a JSON
74
+ object under the JSON-LD context defined in ALI. In the `ali` gem, the
75
+ `Ali::Container` class is used to represent the root element of the ALI
76
+ document.
77
+
78
+ === Usage with XML
79
+
80
+ When parsing ALI in XML, you need to incorporate the ALI element
81
+ classes in the context of the XML document.
82
+
83
+ [example]
84
+ ====
85
+ Usage of ALI elements in XML is not contained in a particular element.
86
+
87
+ [source,xml]
88
+ ----
89
+ <external-document ...>
90
+ <!-- other elements -->
91
+ <free_to_read xmlns="http://www.niso.org/schemas/ali/1.0/"
92
+ start_date="2014-01-01" end_date="2014-12-31"/>
93
+ <license_ref xmlns="http://www.niso.org/schemas/ali/1.0/"
94
+ start_date="2015-02-03">
95
+ http://www.examplesite.org/open_license.html
96
+ </license_ref>
97
+ <!-- other elements -->
98
+ </external-document>
99
+ ----
100
+ ====
101
+
102
+ .Usage with XML
103
+ [source,ruby]
104
+ ----
105
+ > require 'ali'
106
+ > xml = '<free_to_read xmlns="http://www.niso.org/schemas/ali/1.0/" start_date="2014-01-01"
107
+ end_date="2014-12-31"/>'
108
+ > free_to_read = Ali::FreeToRead.from_xml(xml)
109
+ > free_to_read.start_date
110
+ # => "2014-01-01"
111
+ > free_to_read.end_date
112
+ # => "2014-12-31"
113
+ ----
114
+
115
+ === Usage with JSON
116
+
117
+ When parsing ALI in JSON, you need to use the `Ali::Container` class to
118
+ parse the root element of the ALI object.
119
+
120
+ [example]
121
+ ====
122
+ Usage of ALI in JSON-LD is contained in an JSON object.
123
+
124
+ [source,json]
125
+ ----
126
+ {
127
+ "@context": "http://www.niso.org/schemas/ali/1.0.1/jsonld.json",
128
+ "free_to_read": {
129
+ "start_date": "2014-01-01",
130
+ "end_date": "2014-12-31"
131
+ },
132
+ "license_ref": {
133
+ "start_date": "2014-04-04",
134
+ "uri": "http://creativecommons.org/licenses/by/3.0/"
135
+ }
136
+ }
137
+ ----
138
+ ====
139
+
140
+ .Usage with JSON
141
+ [source,ruby]
142
+ ----
143
+ > require 'ali'
144
+ > json = '{"free_to_read": {"start_date": "2014-01-01", "end_date": "2014-12-31"}}'
145
+ > container = Ali::Container.from_json(json)
146
+ > free_to_read = container.free_to_read
147
+ > free_to_read.start_date
148
+ # => "2014-01-01"
149
+ > free_to_read.end_date
150
+ # => "2014-12-31"
151
+ ----
152
+
153
+
154
+ == Tests
155
+
156
+ The `spec/fixtures` folder tests the library against known examples of ALI.
157
+
158
+ Including:
159
+
160
+ `spec/fixtures/json`:: JSON examples from
161
+ https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021], A.4.
162
+
163
+ `spec/fixtures/xml`:: XML examples from
164
+ https://www.niso.org/publications/rp-22-2021-ali[NISO RP 22-2021], A.1.
165
+
166
+
167
+ == License
168
+
169
+ Copyright Ribose.
170
+
171
+ BSD-3 license.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/ali.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ali/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ali"
7
+ spec.version = Ali::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com'"]
10
+
11
+ spec.summary = "NISO Access and License Indicators (ALI) Schemas library"
12
+ spec.description = "A Ruby library for parsing and generating NISO Access and License Indicators (ALI) Schemas data"
13
+ spec.homepage = "https://github.com/lutaml/ali"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/lutaml/ali/releases"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem
22
+ # that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`
25
+ .split("\x0")
26
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.required_ruby_version = ">= 3.0.0"
33
+
34
+ spec.add_dependency "lutaml-model"
35
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ali"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ali
4
+ # The container is only used in the case of JSON and is not from the NISO ALI
5
+ # spec. The NISO ALI contains multiple JSON examples stored in object form
6
+ # that assumes an object container to parse.
7
+ class Container < Lutaml::Model::Serializable
8
+ attribute :free_to_read, FreeToRead, collection: true
9
+ attribute :license_ref, LicenseRef, collection: true
10
+
11
+ xml do
12
+ root "ali-container"
13
+ namespace "http://www.niso.org/schemas/ali/1.0/"
14
+
15
+ map_element "free_to_read", to: :free_to_read
16
+ map_element "license_ref", to: :license_ref
17
+ end
18
+
19
+ json do
20
+ map "free_to_read", to: :free_to_read
21
+ map "license_ref", to: :license_ref
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ali
4
+ class FreeToRead < Lutaml::Model::Serializable
5
+ attribute :start_date, :date
6
+ attribute :end_date, :date
7
+
8
+ xml do
9
+ root "free_to_read"
10
+ namespace "http://www.niso.org/schemas/ali/1.0/"
11
+
12
+ map_attribute "start_date", to: :start_date
13
+ map_attribute "end_date", to: :end_date
14
+ end
15
+
16
+ json do
17
+ map "start_date", to: :start_date
18
+ map "end_date", to: :end_date
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ali
4
+ class LicenseRef < Lutaml::Model::Serializable
5
+ attribute :start_date, :date
6
+ attribute :applies_to, :string
7
+ attribute :uri, :string
8
+
9
+ xml do
10
+ root "license_ref"
11
+ namespace "http://www.niso.org/schemas/ali/1.0/"
12
+
13
+ map_attribute "start_date", to: :start_date
14
+ map_attribute "applies_to", to: :applies_to
15
+ map_content to: :uri
16
+ end
17
+
18
+ json do
19
+ map "start_date", to: :start_date
20
+ map "applies_to", to: :applies_to
21
+ map "uri", to: :uri
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ali
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ali.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ali/version"
4
+ require "lutaml/model"
5
+
6
+ module Ali
7
+ class Error < StandardError; end
8
+
9
+ # Your code goes here...
10
+ end
11
+
12
+ require_relative "ali/free_to_read"
13
+ require_relative "ali/license_ref"
14
+ require_relative "ali/container"
data/sig/ali.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Ali
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ali
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lutaml-model
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A Ruby library for parsing and generating NISO Access and License Indicators
28
+ (ALI) Schemas data
29
+ email:
30
+ - open.source@ribose.com'
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/workflows/rake.yml"
36
+ - ".github/workflows/release.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".rubocop_todo.yml"
41
+ - Gemfile
42
+ - README.adoc
43
+ - Rakefile
44
+ - ali.gemspec
45
+ - bin/console
46
+ - bin/setup
47
+ - lib/ali.rb
48
+ - lib/ali/container.rb
49
+ - lib/ali/free_to_read.rb
50
+ - lib/ali/license_ref.rb
51
+ - lib/ali/version.rb
52
+ - sig/ali.rbs
53
+ homepage: https://github.com/lutaml/ali
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/lutaml/ali
58
+ source_code_uri: https://github.com/lutaml/ali
59
+ changelog_uri: https://github.com/lutaml/ali/releases
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.5.22
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: NISO Access and License Indicators (ALI) Schemas library
79
+ test_files: []