relaton-un 0.1.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/grammars/biblio.rng +144 -49
- data/grammars/isodoc.rng +54 -5
- data/grammars/un.rng +107 -1
- data/lib/relaton_un.rb +3 -1
- data/lib/relaton_un/editorialgroup.rb +25 -0
- data/lib/relaton_un/hash_converter.rb +29 -1
- data/lib/relaton_un/hit.rb +108 -15
- data/lib/relaton_un/hit_collection.rb +124 -47
- data/lib/relaton_un/session.rb +65 -0
- data/lib/relaton_un/un_bibliographic_item.rb +37 -1
- data/lib/relaton_un/un_bibliography.rb +8 -5
- data/lib/relaton_un/version.rb +1 -1
- data/lib/relaton_un/xml_parser.rb +50 -5
- data/relaton_un.gemspec +14 -12
- metadata +19 -16
@@ -1,8 +1,44 @@
|
|
1
1
|
module RelatonUn
|
2
|
-
class UnBibliographicItem <
|
2
|
+
class UnBibliographicItem < RelatonIsoBib::IsoBibliographicItem
|
3
3
|
TYPES = %w[
|
4
4
|
recommendation plenary addendum communication corrigendum reissue agenda
|
5
5
|
budgetary sec-gen-notes expert-report resolution
|
6
6
|
].freeze
|
7
|
+
|
8
|
+
DISTRIBUTIONS = { "GEN" => "general", "LTD" => "limited",
|
9
|
+
"DER" => "restricted", "PRO" => "provisional" }.freeze
|
10
|
+
|
11
|
+
# @return [RelatonUn::Session, NilClass]
|
12
|
+
attr_reader :session
|
13
|
+
|
14
|
+
# @return [String, NilClass]
|
15
|
+
attr_reader :distribution
|
16
|
+
|
17
|
+
# @param session [RelatonUn::Session, NilClass]
|
18
|
+
# @param distribution [String]
|
19
|
+
def initialize(**args)
|
20
|
+
if args[:distribution] && !DISTRIBUTIONS.has_value?(args[:distribution])
|
21
|
+
warn "[relaton-un] WARNING: invalid distribution: #{args[:distribution]}"
|
22
|
+
end
|
23
|
+
@distribution = args.delete :distribution
|
24
|
+
@session = args.delete :session
|
25
|
+
super **args
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param builder [Nokogiri::XML::Builder]
|
29
|
+
# @param bibdata [TrueClasss, FalseClass, NilClass]
|
30
|
+
def to_xml(builder = nil, **opts)
|
31
|
+
super(builder, **opts) do |b|
|
32
|
+
b.distribution distribution if distribution
|
33
|
+
session&.to_xml b if session
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Hash]
|
38
|
+
def to_hash
|
39
|
+
hash = super
|
40
|
+
hash["session"] = session.to_hash if session
|
41
|
+
hash
|
42
|
+
end
|
7
43
|
end
|
8
44
|
end
|
@@ -9,9 +9,11 @@ module RelatonUn
|
|
9
9
|
def search(text)
|
10
10
|
HitCollection.new text
|
11
11
|
rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
12
|
-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
13
|
-
OpenSSL::SSL::SSLError,
|
14
|
-
|
12
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
13
|
+
Net::ProtocolError, Net::ReadTimeout, OpenSSL::SSL::SSLError,
|
14
|
+
Errno::ETIMEDOUT => e
|
15
|
+
raise RelatonBib::RequestError,
|
16
|
+
"Could not access #{HitCollection::DOMAIN}: #{e.message}"
|
15
17
|
end
|
16
18
|
|
17
19
|
# @param ref [String] document reference
|
@@ -23,7 +25,8 @@ module RelatonUn
|
|
23
25
|
/^(UN\s)?(?<code>.*)/ =~ ref
|
24
26
|
result = isobib_search_filter(code)
|
25
27
|
if result
|
26
|
-
warn "[relaton-un] (\"#{ref}\")
|
28
|
+
warn "[relaton-un] (\"#{ref}\") "\
|
29
|
+
"found #{result.fetch.docidentifier[0].id}"
|
27
30
|
result.fetch
|
28
31
|
end
|
29
32
|
end
|
@@ -36,7 +39,7 @@ module RelatonUn
|
|
36
39
|
# @return [RelatonUn::HitCollection]
|
37
40
|
def isobib_search_filter(code)
|
38
41
|
result = search(code)
|
39
|
-
result.select { |i| i.hit[:
|
42
|
+
result.select { |i| i.hit[:symbol].include? code }.first
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
data/lib/relaton_un/version.rb
CHANGED
@@ -1,16 +1,61 @@
|
|
1
1
|
module RelatonUn
|
2
|
-
class XMLParser <
|
2
|
+
class XMLParser < RelatonIsoBib::XMLParser
|
3
3
|
class << self
|
4
|
+
# @param xml [String]
|
5
|
+
# @return [RelatonUn::UnBibliographicItem, NilClass]
|
4
6
|
def from_xml(xml)
|
5
7
|
doc = Nokogiri::XML xml
|
6
8
|
doc.remove_namespaces!
|
7
|
-
|
8
|
-
if
|
9
|
-
UnBibliographicItem.new(item_data(
|
9
|
+
item = doc.at("/bibitem|/bibdata")
|
10
|
+
if item
|
11
|
+
UnBibliographicItem.new(item_data(item))
|
10
12
|
else
|
11
|
-
warn "[relaton-un] can't find bibitem or bibdata element in
|
13
|
+
warn "[relaton-un] WARNING: can't find bibitem or bibdata element in"\
|
14
|
+
" the XML"
|
12
15
|
end
|
13
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# @param item [Nokogiri::XML::Element]
|
21
|
+
# @return [Hash]
|
22
|
+
def item_data(item)
|
23
|
+
data = super
|
24
|
+
data[:session] = fetch_session item
|
25
|
+
data[:distribution] = item.at("distribution")&.text
|
26
|
+
data
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
30
|
+
|
31
|
+
# @param item [Nokogiri::XML::Element]
|
32
|
+
# @return [RelatonUn::Session]
|
33
|
+
def fetch_session(item)
|
34
|
+
session = item.at "./ext/session"
|
35
|
+
return unless session
|
36
|
+
|
37
|
+
RelatonUn::Session.new(
|
38
|
+
session_number: session.at("number")&.text,
|
39
|
+
session_date: session.at("session-date")&.text,
|
40
|
+
item_number: session.xpath("item-number").map(&:text),
|
41
|
+
item_name: session.xpath("item-name").map(&:text),
|
42
|
+
subitem_name: session.xpath("subitem-name").map(&:text),
|
43
|
+
collaboration: session.at("collaboration")&.text,
|
44
|
+
agenda_id: session.at("agenda-id")&.text,
|
45
|
+
item_footnote: session.at("item-footnote")&.text,
|
46
|
+
)
|
47
|
+
end
|
48
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
49
|
+
|
50
|
+
# @param ext [Nokogiri::XML::Element]
|
51
|
+
# @return [RelatonUn::EditorialGroup]
|
52
|
+
def fetch_editorialgroup(ext)
|
53
|
+
eg = ext.at("./editorialgroup")
|
54
|
+
return unless eg
|
55
|
+
|
56
|
+
committee = eg&.xpath("committee")&.map &:text
|
57
|
+
EditorialGroup.new committee
|
58
|
+
end
|
14
59
|
end
|
15
60
|
end
|
16
61
|
end
|
data/relaton_un.gemspec
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require "relaton_un/version"
|
4
4
|
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
5
6
|
Gem::Specification.new do |spec|
|
6
7
|
spec.name = "relaton-un"
|
7
8
|
spec.version = RelatonUn::VERSION
|
8
9
|
spec.authors = ["Ribose Inc."]
|
9
10
|
spec.email = ["open.source@ribose.com"]
|
10
11
|
|
11
|
-
spec.summary = "RelatonIso: retrieve CC Standards for bibliographic
|
12
|
-
"using the IsoBibliographicItem model"
|
13
|
-
spec.description = "RelatonIso: retrieve CC Standards for bibliographic
|
14
|
-
"using the IsoBibliographicItem model"
|
12
|
+
spec.summary = "RelatonIso: retrieve CC Standards for bibliographic "\
|
13
|
+
"use using the IsoBibliographicItem model"
|
14
|
+
spec.description = "RelatonIso: retrieve CC Standards for bibliographic "\
|
15
|
+
"use using the IsoBibliographicItem model"
|
15
16
|
spec.homepage = "https://github.com/relaton/relaton-un"
|
16
17
|
spec.license = "BSD-2-Clause"
|
17
18
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
18
19
|
|
19
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
-
|
21
20
|
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
-
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
23
22
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
23
|
|
25
24
|
# Specify which files should be added to the gem when it is released.
|
26
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
-
spec.files
|
28
|
-
`git ls-files -z`.split("\x0").reject
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
29
30
|
end
|
30
31
|
spec.bindir = "exe"
|
31
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -40,8 +41,9 @@ Gem::Specification.new do |spec|
|
|
40
41
|
spec.add_development_dependency "vcr"
|
41
42
|
spec.add_development_dependency "webmock"
|
42
43
|
|
43
|
-
spec.add_dependency "unf_ext", ">= 0.0.7.7"
|
44
44
|
spec.add_dependency "faraday"
|
45
45
|
spec.add_dependency "http-cookie"
|
46
|
-
spec.add_dependency "relaton-bib", "~>
|
46
|
+
spec.add_dependency "relaton-iso-bib", "~> 1.1.0"
|
47
|
+
spec.add_dependency "unf_ext", ">= 0.0.7.7"
|
47
48
|
end
|
49
|
+
# rubocop:enable Metrics/BlockLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-un
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|
@@ -123,21 +123,21 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: faraday
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0
|
131
|
+
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: http-cookie
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,33 +151,33 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: relaton-iso-bib
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 1.1.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 1.1.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: unf_ext
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 0.
|
173
|
+
version: 0.0.7.7
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 0.
|
180
|
+
version: 0.0.7.7
|
181
181
|
description: 'RelatonIso: retrieve CC Standards for bibliographic use using the IsoBibliographicItem
|
182
182
|
model'
|
183
183
|
email:
|
@@ -205,10 +205,12 @@ files:
|
|
205
205
|
- grammars/reqt.rng
|
206
206
|
- grammars/un.rng
|
207
207
|
- lib/relaton_un.rb
|
208
|
+
- lib/relaton_un/editorialgroup.rb
|
208
209
|
- lib/relaton_un/hash_converter.rb
|
209
210
|
- lib/relaton_un/hit.rb
|
210
211
|
- lib/relaton_un/hit_collection.rb
|
211
212
|
- lib/relaton_un/processor.rb
|
213
|
+
- lib/relaton_un/session.rb
|
212
214
|
- lib/relaton_un/un_bibliographic_item.rb
|
213
215
|
- lib/relaton_un/un_bibliography.rb
|
214
216
|
- lib/relaton_un/version.rb
|
@@ -220,6 +222,7 @@ licenses:
|
|
220
222
|
- BSD-2-Clause
|
221
223
|
metadata:
|
222
224
|
homepage_uri: https://github.com/relaton/relaton-un
|
225
|
+
source_code_uri: https://github.com/relaton/relaton-un
|
223
226
|
post_install_message:
|
224
227
|
rdoc_options: []
|
225
228
|
require_paths:
|