relaton-cie 1.7.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/reqt.rng ADDED
@@ -0,0 +1,165 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!--
4
+ Presupposes isodoc.rnc, is included in it
5
+ include "isodoc.rnc" { }
6
+ -->
7
+ <define name="requirement">
8
+ <element name="requirement">
9
+ <ref name="RequirementType"/>
10
+ </element>
11
+ </define>
12
+ <define name="recommendation">
13
+ <element name="recommendation">
14
+ <ref name="RequirementType"/>
15
+ </element>
16
+ </define>
17
+ <define name="permission">
18
+ <element name="permission">
19
+ <ref name="RequirementType"/>
20
+ </element>
21
+ </define>
22
+ <define name="RequirementType">
23
+ <optional>
24
+ <attribute name="obligation">
25
+ <ref name="ObligationType"/>
26
+ </attribute>
27
+ </optional>
28
+ <optional>
29
+ <attribute name="unnumbered">
30
+ <data type="boolean"/>
31
+ </attribute>
32
+ </optional>
33
+ <optional>
34
+ <attribute name="subsequence"/>
35
+ </optional>
36
+ <attribute name="id">
37
+ <data type="ID"/>
38
+ </attribute>
39
+ <optional>
40
+ <attribute name="filename"/>
41
+ </optional>
42
+ <optional>
43
+ <ref name="reqtitle"/>
44
+ </optional>
45
+ <optional>
46
+ <ref name="label"/>
47
+ </optional>
48
+ <optional>
49
+ <ref name="subject"/>
50
+ </optional>
51
+ <optional>
52
+ <ref name="reqinherit"/>
53
+ </optional>
54
+ <zeroOrMore>
55
+ <ref name="classification"/>
56
+ </zeroOrMore>
57
+ <zeroOrMore>
58
+ <choice>
59
+ <ref name="measurementtarget"/>
60
+ <ref name="specification"/>
61
+ <ref name="verification"/>
62
+ <ref name="import"/>
63
+ <ref name="description"/>
64
+ </choice>
65
+ </zeroOrMore>
66
+ <optional>
67
+ <ref name="reqt_references"/>
68
+ </optional>
69
+ <zeroOrMore>
70
+ <choice>
71
+ <ref name="requirement"/>
72
+ <ref name="recommendation"/>
73
+ <ref name="permission"/>
74
+ </choice>
75
+ </zeroOrMore>
76
+ </define>
77
+ <define name="reqtitle">
78
+ <element name="title">
79
+ <ref name="FormattedString"/>
80
+ </element>
81
+ </define>
82
+ <define name="label">
83
+ <element name="label">
84
+ <text/>
85
+ </element>
86
+ </define>
87
+ <define name="subject">
88
+ <element name="subject">
89
+ <text/>
90
+ </element>
91
+ </define>
92
+ <define name="reqinherit">
93
+ <element name="inherit">
94
+ <text/>
95
+ </element>
96
+ </define>
97
+ <define name="measurementtarget">
98
+ <element name="measurement-target">
99
+ <ref name="RequirementSubpart"/>
100
+ </element>
101
+ </define>
102
+ <define name="specification">
103
+ <element name="specification">
104
+ <ref name="RequirementSubpart"/>
105
+ </element>
106
+ </define>
107
+ <define name="verification">
108
+ <element name="verification">
109
+ <ref name="RequirementSubpart"/>
110
+ </element>
111
+ </define>
112
+ <define name="import">
113
+ <element name="import">
114
+ <ref name="RequirementSubpart"/>
115
+ </element>
116
+ </define>
117
+ <define name="description">
118
+ <element name="description">
119
+ <ref name="RequirementSubpart"/>
120
+ </element>
121
+ </define>
122
+ <define name="reqt_references">
123
+ <element name="references">
124
+ <oneOrMore>
125
+ <ref name="bibitem"/>
126
+ </oneOrMore>
127
+ </element>
128
+ </define>
129
+ <define name="RequirementSubpart">
130
+ <optional>
131
+ <attribute name="type"/>
132
+ </optional>
133
+ <optional>
134
+ <attribute name="exclude">
135
+ <data type="boolean"/>
136
+ </attribute>
137
+ </optional>
138
+ <oneOrMore>
139
+ <ref name="BasicBlock"/>
140
+ </oneOrMore>
141
+ </define>
142
+ <define name="ObligationType">
143
+ <choice>
144
+ <value>requirement</value>
145
+ <value>recommendation</value>
146
+ <value>permission</value>
147
+ </choice>
148
+ </define>
149
+ <define name="classification">
150
+ <element name="classification">
151
+ <ref name="classification_tag"/>
152
+ <ref name="classification_value"/>
153
+ </element>
154
+ </define>
155
+ <define name="classification_tag">
156
+ <element name="tag">
157
+ <text/>
158
+ </element>
159
+ </define>
160
+ <define name="classification_value">
161
+ <element name="value">
162
+ <text/>
163
+ </element>
164
+ </define>
165
+ </grammar>
@@ -0,0 +1,17 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "relaton_bib"
4
+ require "relaton_cie/version"
5
+ require "relaton_cie/cie_bibliography"
6
+ require "relaton_cie/scrapper"
7
+
8
+ module RelatonCie
9
+ # Returns hash of XML reammar
10
+ # @return [String]
11
+ def self.grammar_hash
12
+ gem_path = File.expand_path "..", __dir__
13
+ grammars_path = File.join gem_path, "grammars", "*"
14
+ grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
15
+ Digest::MD5.hexdigest grammars
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal:true
2
+
3
+ module RelatonCie
4
+ # IETF bibliography module
5
+ module CieBibliography
6
+ class << self
7
+ # @param code [String] the ECMA standard Code to look up (e..g "ECMA-6")
8
+ # @return [RelatonBib::BibliographicEcma]
9
+ def search(code)
10
+ Scrapper.scrape_page code
11
+ end
12
+
13
+ # @param code [String] the ECMA standard Code to look up (e..g "ECMA-6")
14
+ # @param year [String] not used
15
+ # @param opts [Hash] not used
16
+ # @return [RelatonBib::BibliographicItem] Relaton of reference
17
+ def get(code, _year = nil, _opts = {})
18
+ warn "[relaton-cie] (\"#{code}\") fetching..."
19
+ result = search code
20
+ if result
21
+ warn "[relaton-cie] (\"#{code}\") found #{result.docidentifier.first.id}"
22
+ else
23
+ warn "[relaton-cie] WARNING no match found online for #{code}. "\
24
+ "The code must be exactly like it is on the standards website."
25
+ end
26
+ result
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ require "relaton/processor"
2
+
3
+ module RelatonCie
4
+ class Processor < Relaton::Processor
5
+ def initialize
6
+ @short = :relaton_cie
7
+ @prefix = "CIE"
8
+ @defaultprefix = /^CIE(-|\s)/
9
+ @idtype = "CIE"
10
+ end
11
+
12
+ # @param code [String]
13
+ # @param date [String, NilClass] year
14
+ # @param opts [Hash]
15
+ # @return [RelatonBib::BibliographicItem]
16
+ def get(code, date, opts)
17
+ ::RelatonCie::CieBibliography.get(code, date, opts)
18
+ end
19
+
20
+ # @param xml [String]
21
+ # @return [RelatonBib::BibliographicItem]
22
+ def from_xml(xml)
23
+ ::RelatonBib::XMLParser.from_xml xml
24
+ end
25
+
26
+ # @param hash [Hash]
27
+ # @return [RelatonBib::BibliographicItem]
28
+ def hash_to_bib(hash)
29
+ item_hash = ::RelatonBib::HashConverter.hash_to_bib(hash)
30
+ ::RelatonBib::BibliographicItem.new item_hash
31
+ end
32
+
33
+ # Returns hash of XML grammar
34
+ # @return [String]
35
+ def grammar_hash
36
+ @grammar_hash ||= ::RelatonEcma.grammar_hash
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ module RelatonCie
2
+ module Scrapper
3
+ ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-cie/master/data/".freeze
4
+
5
+ class << self
6
+ # @param code [String]
7
+ # @return [RelatonBib::BibliographicItem]
8
+ def scrape_page(code)
9
+ url = "#{ENDPOINT}#{code.gsub(/[\/\s\-:\.]/, '_').upcase}.yaml"
10
+ parse_page url
11
+ rescue OpenURI::HTTPError => e
12
+ return if e.io.status.first == "404"
13
+
14
+ raise RelatonBib::RequestError, "No document found for #{code} reference. #{e.message}"
15
+ end
16
+
17
+ private
18
+
19
+ # @param url [String]
20
+ # @retrurn [RelatonBib::BibliographicItem]
21
+ def parse_page(url)
22
+ doc = OpenURI.open_uri url
23
+ bib_hash = RelatonBib::HashConverter.hash_to_bib YAML.safe_load(doc)
24
+ RelatonBib::BibliographicItem.new **bib_hash
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module RelatonCie
2
+ VERSION = "1.7.pre1".freeze
3
+ end
@@ -0,0 +1,43 @@
1
+ require_relative "lib/relaton_cie/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "relaton-cie"
5
+ spec.version = RelatonCie::VERSION
6
+ spec.authors = ["Ribose Inc."]
7
+ spec.email = ["open.source@ribose.com"]
8
+
9
+ spec.summary = <<~DESCRIPTION
10
+ RelatonEcma: retrieve CIE Standards for bibliographic use
11
+ using the BibliographicItem model.
12
+ DESCRIPTION
13
+ spec.description = <<~DESCRIPTION
14
+ RelatonEcma: retrieve CIE Standards for bibliographic use
15
+ using the BibliographicItem model.
16
+ DESCRIPTION
17
+ spec.homepage = "https://github.com/metanorma/relaton-cie"
18
+ spec.license = "BSD-2-Clause"
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").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.add_development_dependency "debase"
33
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
34
+ spec.add_development_dependency "pry-byebug"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ # spec.add_development_dependency "ruby-debug-ide"
37
+ spec.add_development_dependency "ruby-jing"
38
+ spec.add_development_dependency "simplecov"
39
+ spec.add_development_dependency "vcr"
40
+ spec.add_development_dependency "webmock"
41
+
42
+ spec.add_dependency "relaton-bib", "~> 1.7.0"
43
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-cie
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: equivalent-xml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-jing
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: relaton-bib
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.7.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.7.0
125
+ description: "RelatonEcma: retrieve CIE Standards for bibliographic use \nusing the
126
+ BibliographicItem model.\n"
127
+ email:
128
+ - open.source@ribose.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".github/workflows/rake.yml"
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".rubocop.yml"
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.adoc
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - grammars/basicdoc.rng
144
+ - grammars/biblio.rng
145
+ - grammars/isodoc.rng
146
+ - grammars/reqt.rng
147
+ - lib/relaton_cie.rb
148
+ - lib/relaton_cie/cie_bibliography.rb
149
+ - lib/relaton_cie/processor.rb
150
+ - lib/relaton_cie/scrapper.rb
151
+ - lib/relaton_cie/version.rb
152
+ - relaton_cie.gemspec
153
+ homepage: https://github.com/metanorma/relaton-cie
154
+ licenses:
155
+ - BSD-2-Clause
156
+ metadata:
157
+ homepage_uri: https://github.com/metanorma/relaton-cie
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 2.4.0
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">"
170
+ - !ruby/object:Gem::Version
171
+ version: 1.3.1
172
+ requirements: []
173
+ rubygems_version: 3.0.6
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: 'RelatonEcma: retrieve CIE Standards for bibliographic use using the BibliographicItem
177
+ model.'
178
+ test_files: []