relaton-un 0.2.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ module RelatonUn
29
29
  # @return [RelatonIsoBib::IsoBibliographicItem]
30
30
  def hash_to_bib(hash)
31
31
  item_hash = ::RelatonUn::HashConverter.hash_to_bib(hash)
32
- ::RelatonIsoBib::UnBibliographicItem.new item_hash
32
+ ::RelatonUn::UnBibliographicItem.new item_hash
33
33
  end
34
34
 
35
35
  # Returns hash of XML grammar
@@ -0,0 +1,65 @@
1
+ module RelatonUn
2
+ class Session
3
+ include RelatonBib
4
+
5
+ # @return [String, NilClass]
6
+ attr_reader :session_number, :collaboration, :agenda_id, :item_footnote
7
+
8
+ # @return [Date, NilClass]
9
+ attr_reader :session_date
10
+
11
+ # @return [Array<String>]
12
+ attr_reader :item_number, :item_name, :subitem_name
13
+
14
+ # @param session_number [String]
15
+ # @param session_date [String]
16
+ # @param item_number [Array<String>]
17
+ # @pqrqm item_name [Array<String>]
18
+ # @pqrqm subitem_name [Array<String>]
19
+ # @param collaboration [String]
20
+ # @param agenda_id [String]
21
+ # @param item_footnote [String]
22
+ def initialize(**args)
23
+ @session_number = args[:session_number]
24
+ @session_date = Date.parse args[:session_date] if args[:session_date]
25
+ @item_number = args.fetch(:item_number, [])
26
+ @item_name = args.fetch(:item_name, [])
27
+ @subitem_name = args.fetch(:subitem_name, [])
28
+ @collaboration = args[:collaboration]
29
+ @agenda_id = args[:agenda_id]
30
+ @item_footnote = args[:item_footnote]
31
+ end
32
+
33
+ # rubocop:disable Metrics/AbcSize
34
+
35
+ # @param [Nokogiri::XML::Builder]
36
+ def to_xml(builder)
37
+ builder.session do |b|
38
+ b.number session_number if session_number
39
+ b.send "session-date", session_date.to_s if session_date
40
+ item_number.each { |n| b.send "item-number", n }
41
+ item_name.each { |n| b.send "item-name", n }
42
+ subitem_name.each { |n| b.send "subitem-name", n }
43
+ b.collaboration collaboration if collaboration
44
+ b.send "agenda-id", agenda_id if agenda_id
45
+ b.send "item-footnote", item_footnote if item_footnote
46
+ end
47
+ end
48
+
49
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
50
+ # @return [Hash]
51
+ def to_hash
52
+ hash = {}
53
+ hash["session_number"] = session_number if session_number
54
+ hash["session_date"] = session_date.to_s if session_date
55
+ hash["item_number"] = single_element_array(item_number) if item_number.any?
56
+ hash["item_name"] = single_element_array(item_name) if item_name.any?
57
+ hash["subitem_name"] = single_element_array(subitem_name) if subitem_name.any?
58
+ hash["collaboration"] = collaboration if collaboration
59
+ hash["agenda_id"] = agenda_id if agenda_id
60
+ hash["item_footnote"] = item_footnote if item_footnote
61
+ hash
62
+ end
63
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
64
+ end
65
+ end
@@ -4,5 +4,45 @@ module RelatonUn
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
+ # @doctype = args[:doctype]
27
+ end
28
+
29
+ # @param builder [Nokogiri::XML::Builder]
30
+ # @param bibdata [TrueClasss, FalseClass, NilClass]
31
+ def to_xml(builder = nil, **opts)
32
+ super(builder, **opts) do |b|
33
+ b.ext do
34
+ editorialgroup&.to_xml b
35
+ b.distribution distribution if distribution
36
+ session&.to_xml b if session
37
+ end
38
+ end
39
+ end
40
+
41
+ # @return [Hash]
42
+ def to_hash
43
+ hash = super
44
+ hash["session"] = session.to_hash if session
45
+ hash
46
+ end
7
47
  end
8
48
  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, Net::ProtocolError,
13
- OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
14
- raise RelatonBib::RequestError, "Could not access #{HitCollection::DOMAIN}"
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}\") found #{result.fetch.docidentifier.first.id}"
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[:ref] == code }.first
42
+ result.select { |i| i.hit[:symbol].include? code }.first
40
43
  end
41
44
  end
42
45
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonUn
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
@@ -1,15 +1,52 @@
1
1
  module RelatonUn
2
2
  class XMLParser < RelatonBib::XMLParser
3
3
  class << self
4
- def from_xml(xml)
5
- doc = Nokogiri::XML xml
6
- doc.remove_namespaces!
7
- titem = doc.at("/bibitem|/bibdata")
8
- if titem
9
- UnBibliographicItem.new(item_data(titem))
10
- else
11
- warn "[relaton-un] can't find bibitem or bibdata element in the XML"
12
- end
4
+ private
5
+
6
+ # @param item_hash [Hash]
7
+ # @return [RelatonBib::BibliographicItem]
8
+ def bib_item(item_hash)
9
+ UnBibliographicItem.new item_hash
10
+ end
11
+
12
+ # @param item [Nokogiri::XML::Element]
13
+ # @return [Hash]
14
+ def item_data(item)
15
+ data = super
16
+ data[:session] = fetch_session item
17
+ data[:distribution] = item.at("distribution")&.text
18
+ data
19
+ end
20
+
21
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
22
+
23
+ # @param item [Nokogiri::XML::Element]
24
+ # @return [RelatonUn::Session]
25
+ def fetch_session(item)
26
+ session = item.at "./ext/session"
27
+ return unless session
28
+
29
+ RelatonUn::Session.new(
30
+ session_number: session.at("number")&.text,
31
+ session_date: session.at("session-date")&.text,
32
+ item_number: session.xpath("item-number").map(&:text),
33
+ item_name: session.xpath("item-name").map(&:text),
34
+ subitem_name: session.xpath("subitem-name").map(&:text),
35
+ collaboration: session.at("collaboration")&.text,
36
+ agenda_id: session.at("agenda-id")&.text,
37
+ item_footnote: session.at("item-footnote")&.text,
38
+ )
39
+ end
40
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
41
+
42
+ # @param ext [Nokogiri::XML::Element]
43
+ # @return [RelatonUn::EditorialGroup]
44
+ def fetch_editorialgroup(ext)
45
+ eg = ext.at("./editorialgroup")
46
+ return unless eg
47
+
48
+ committee = eg&.xpath("committee")&.map &:text
49
+ EditorialGroup.new committee
13
50
  end
14
51
  end
15
52
  end
@@ -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 'relaton_un/version'
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 use "\
12
- "using the IsoBibliographicItem model"
13
- spec.description = "RelatonIso: retrieve CC Standards for bibliographic use "\
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
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
28
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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) }
@@ -42,6 +43,7 @@ Gem::Specification.new do |spec|
42
43
 
43
44
  spec.add_dependency "faraday"
44
45
  spec.add_dependency "http-cookie"
45
- spec.add_dependency "relaton-bib", "~> 0.9.0"
46
+ spec.add_dependency "relaton-bib", "~> 1.2.0"
46
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: 0.2.0
4
+ version: 1.2.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-30 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.9.0
159
+ version: 1.2.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: 0.9.0
166
+ version: 1.2.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: unf_ext
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -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: