relaton-ecma 1.7.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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_ecma/version"
5
+ require "relaton_ecma/scrapper"
6
+ require "relaton_ecma/ecma_bibliography"
7
+
8
+ module RelatonEcma
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 RelatonEcma
4
+ # IETF bibliography module
5
+ module EcmaBibliography
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-ecma] (\"#{code}\") fetching..."
19
+ result = search code
20
+ if result
21
+ warn "[relaton-ecma] (\"#{code}\") found #{result.docidentifier.first.id}"
22
+ else
23
+ warn "[relaton-ecma] 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 RelatonEcma
4
+ class Processor < Relaton::Processor
5
+ def initialize
6
+ @short = :relaton_ecma
7
+ @prefix = "ECMA"
8
+ @defaultprefix = /^ECMA(-|\s)/
9
+ @idtype = "ECMA"
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
+ ::RelatonEcma::EcmaBibliography.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,99 @@
1
+ module RelatonEcma
2
+ module Scrapper
3
+ ENDPOINT = "https://www.ecma-international.org/publications/standards/".freeze
4
+
5
+ class << self
6
+ # @param code [String]
7
+ # @return [RelatonBib::BibliographicItem]
8
+ def scrape_page(code) # rubocop:disable Metrics/AbcSize
9
+ num = /\d+$/.match(code).to_s.rjust 3, "0"
10
+ url = ENDPOINT + code.capitalize.sub(/\d+$/, num) + ".htm"
11
+ doc = Nokogiri::HTML OpenURI.open_uri url
12
+ parse_page doc, code, url
13
+ rescue OpenURI::HTTPError => e
14
+ return if e.io.status.first == "404"
15
+
16
+ raise RelatonBib::RequestError, "No document found for #{code} reference. #{e.message}"
17
+ end
18
+
19
+ private
20
+
21
+ # @param doc [Nokogiri::HTML::Document]
22
+ # @param code [String]
23
+ # @param url [String]
24
+ # @retrurn [RelatonBib::BibliographicItem]
25
+ def parse_page(doc, code, url)
26
+ RelatonBib::BibliographicItem.new(
27
+ type: "standard", docid: fetch_docid(code), language: ["en"], script: ["Latn"],
28
+ link: fetch_link(doc, url), title: fetch_title(doc), abstract: fetch_abstract(doc),
29
+ date: fetch_date(doc), relation: fetch_relation(doc), place: ["Geneva"],
30
+ edition: fetch_edition(doc), doctype: "document"
31
+ )
32
+ end
33
+
34
+ # @param code [String]
35
+ # @return [Array<RelatonBib::DocumentIdentifier>]
36
+ def fetch_docid(code)
37
+ [RelatonBib::DocumentIdentifier.new(type: "ECMA", id: code)]
38
+ end
39
+
40
+ # @param doc [Nokogiri::HTM::Document]
41
+ # @param url [String]
42
+ # @return [Array<RelatonBib::TypedUri>]
43
+ def fetch_link(doc, url)
44
+ link = [RelatonBib::TypedUri.new(type: "src", content: url)]
45
+ ref = doc.at('//tr[@class="STbody"]/td/a')
46
+ link << RelatonBib::TypedUri.new(type: "doi", content: ref[:href]) if ref
47
+ link
48
+ end
49
+
50
+ # @param doc [Nokogiri::HTML::Document]
51
+ # @return [Array<Hash>]
52
+ def fetch_title(doc)
53
+ doc.xpath('//span[@class="STsubtitle"]').map do |t|
54
+ { content: t.text.strip, language: "en", script: "Latn" }
55
+ end
56
+ end
57
+
58
+ # @param doc [Nokogiri::HTML::Document]
59
+ # @return [Array<RelatonBib::FormattedString>]
60
+ def fetch_abstract(doc)
61
+ a = doc.xpath('//p[@class="STdescription"]').map do |a|
62
+ a.text.strip.squeeze(" ").gsub /\r\n/, ""
63
+ end.join "\n"
64
+ return [] if a.empty?
65
+
66
+ [RelatonBib::FormattedString.new(content: a, language: "en", script: "Latn")]
67
+ end
68
+
69
+ # @param doc [Nokogiri::HTML::Document]
70
+ # @return [Array<RelatonBib::BibliographicDate>]
71
+ def fetch_date(doc)
72
+ doc.xpath('//span[@class="STedition"]').map do |d|
73
+ date = d.text.match(/(?<=\()\w+\s\d{4}(?=\))/).to_s
74
+ RelatonBib::BibliographicDate.new type: "published", on: date
75
+ end
76
+ end
77
+
78
+ # @param doc [Nokogiri::HTML::Document]
79
+ # @return [String]
80
+ def fetch_edition(doc)
81
+ doc.at('//span[@class="STedition"]')&.text&.strip&.match(/^\d+(?=th)/)&.to_s
82
+ end
83
+
84
+ # @param doc [Nokogiri::HTML::Document]
85
+ # @return [Array<Hash>]
86
+ def fetch_relation(doc)
87
+ history = doc.at "//p[contains(., 'historical')]/a"
88
+ return [] unless history
89
+
90
+ rel_doc = Nokogiri::HTML OpenURI.open_uri(ENDPOINT + history[:href])
91
+ rel_doc.xpath("//tr[@class='STbody']/td[1]/*").map do |rel|
92
+ fref = RelatonBib::FormattedRef.new content: rel.text, language: "en", script: "Latn"
93
+ bibitem = RelatonBib::BibliographicItem.new formattedref: fref
94
+ { type: "updates", bibitem: bibitem }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module RelatonEcma
2
+ VERSION = "1.7.pre1".freeze
3
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "lib/relaton_ecma/version"
2
+
3
+ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
4
+ spec.name = "relaton-ecma"
5
+ spec.version = RelatonEcma::VERSION
6
+ spec.authors = ["Ribose Inc."]
7
+ spec.email = ["open.source@ribose.com"]
8
+
9
+ spec.summary = "RelatonIetf: retrieve ECMA Standards for bibliographic use "\
10
+ "using the BibliographicItem model"
11
+ spec.description = <<~DESCRIPTION
12
+ RelatonEcma: retrieve ECMA Standards for bibliographic use
13
+ using the BibliographicItem model.
14
+ DESCRIPTION
15
+ spec.homepage = "https://github.com/metanorma/relaton-ecma"
16
+ spec.license = "BSD-2-Clause"
17
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "debase"
31
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
32
+ spec.add_development_dependency "pry-byebug"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "ruby-debug-ide"
35
+ spec.add_development_dependency "ruby-jing"
36
+ spec.add_development_dependency "simplecov"
37
+ spec.add_development_dependency "vcr"
38
+ spec.add_development_dependency "webmock"
39
+
40
+ spec.add_dependency "relaton-bib", "~> 1.7.0"
41
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-ecma
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: 2020-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debase
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: equivalent-xml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-debug-ide
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: ruby-jing
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: simplecov
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: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: relaton-bib
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.7.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.7.0
153
+ description: "RelatonEcma: retrieve ECMA Standards for bibliographic use \nusing the
154
+ BibliographicItem model.\n"
155
+ email:
156
+ - open.source@ribose.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".github/workflows/macos.yml"
162
+ - ".github/workflows/ubuntu.yml"
163
+ - ".github/workflows/windows.yml"
164
+ - ".gitignore"
165
+ - ".rspec"
166
+ - ".rubocop.yml"
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.adoc
170
+ - Rakefile
171
+ - bin/console
172
+ - bin/rspec
173
+ - bin/setup
174
+ - grammars/basicdoc.rng
175
+ - grammars/biblio.rng
176
+ - grammars/isodoc.rng
177
+ - grammars/reqt.rng
178
+ - lib/relaton_ecma.rb
179
+ - lib/relaton_ecma/ecma_bibliography.rb
180
+ - lib/relaton_ecma/processor.rb
181
+ - lib/relaton_ecma/scrapper.rb
182
+ - lib/relaton_ecma/version.rb
183
+ - relaton_ecma.gemspec
184
+ homepage: https://github.com/metanorma/relaton-ecma
185
+ licenses:
186
+ - BSD-2-Clause
187
+ metadata:
188
+ homepage_uri: https://github.com/metanorma/relaton-ecma
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: 2.4.0
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">"
201
+ - !ruby/object:Gem::Version
202
+ version: 1.3.1
203
+ requirements: []
204
+ rubygems_version: 3.0.6
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: 'RelatonIetf: retrieve ECMA Standards for bibliographic use using the BibliographicItem
208
+ model'
209
+ test_files: []