relaton-un 1.2.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8126ad17a8daeba18d98bf60b9b058cac2a7980d2bf9dc86135753c7c6d465f4
4
- data.tar.gz: b69257fbdfb2688ccb6a093b5cfd19478c6663d7b894cad2943d493db013d3aa
3
+ metadata.gz: 15db68b8fb83679317777adb635ce62c56044b7685f9b0c7e94bb0040c66fbf7
4
+ data.tar.gz: 5b4eff35e67ad989f8b8c3ffd1cf5a72b974c6ee18605b585b72acdc57cf48da
5
5
  SHA512:
6
- metadata.gz: 23647bafcdd4658c5b28fb522856428821814d477e47fbbc27367d5817a9d56048a8716cfd6312b4d81aa245a73409e3d831024f74cb667f73fa7b4489f2f9cb
7
- data.tar.gz: 8ead46ec5d80a0a751dc4c39da26a07d2371358505f6eea8b442d4448459a225787e10d7af807e13283296dfd162d8353972dcbe1ec5821ef94116b9a383366f
6
+ metadata.gz: 24a85da74d47286a193e3b56fc912de77ddeb912a0a2c8c0b0bd575542dd99d67badb818e171491c2c1704c8336f81a3a9c03b39de2ed63e5044ab1df88a0220
7
+ data.tar.gz: ce0b55e34ff5c2876dbf6c09d9dfa88b09e8c1d497453f48db48e8af0660e679ec932d103937cb85df0ef4d368fc36db12acc20fa1a3d3e7ecad30466123b7cd
@@ -29,4 +29,5 @@ jobs:
29
29
  bundle install --jobs 4 --retry 3
30
30
  - name: Run specs
31
31
  run: |
32
+ unset JAVA_TOOL_OPTIONS
32
33
  bundle exec rake
@@ -5,6 +5,6 @@
5
5
  inherit_from:
6
6
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
7
7
  AllCops:
8
- TargetRubyVersion: 2.3
8
+ TargetRubyVersion: 2.4
9
9
  Rails:
10
- Enabled: true
10
+ Enabled: false
@@ -25,9 +25,10 @@ Or install it yourself as:
25
25
 
26
26
  === Search for a standard using keywords
27
27
 
28
- [source]
28
+ [source,ruby]
29
29
  ----
30
30
  require 'relaton_un'
31
+ => true
31
32
 
32
33
  hits = RelatonUn::UnBibliography.search("TRADE/CEFACT/2004/32")
33
34
  => <RelatonUn::HitCollection:0x007fc4e6ec2018 @ref=TRADE/CEFACT/2004/32 @fetched=false>
@@ -39,23 +40,23 @@ item = hits[0].fetch
39
40
 
40
41
  === XML serialization
41
42
 
42
- [source]
43
+ [source,ruby]
43
44
  ----
44
45
  item.to_xml
45
- => '<bibitem id="TRADE/CEFACT/2004/32">
46
+ => "<bibitem id="TRADE/CEFACT/2004/32" type="standard">
46
47
  <title type="main" format="text/plain" language="en" script="Latn">SECRETARIAT REVIEW OF UN/LOCODE, 19 DECEMBER 2003 / SUBMITTED BY THE SECRETARIAT</title>
47
48
  <uri type="pdf">https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/pdf/G0430683.pdf?OpenElement</uri>
48
49
  <uri type="word">https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/doc/G0430683.DOC?OpenElement</uri>
49
50
  <docidentifier type="UN">TRADE/CEFACT/2004/32</docidentifier>
50
51
  <docnumber>TRADE/CEFACT/2004/32</docnumber>
51
52
  ...
52
- </bibitem>'
53
+ </bibitem>"
53
54
  ----
54
55
  With argument `bibdata: true` it ouputs XML wrapped by `bibdata` element and adds flavour `ext` element.
55
- [source]
56
+ [source,ruby]
56
57
  ----
57
58
  item.to_xml bibdata: true
58
- => '<bibdata type="standard">
59
+ => "<bibdata type="standard">
59
60
  <fetched>2020-03-13</fetched>
60
61
  <title type="main" format="text/plain" language="en" script="Latn">SECRETARIAT REVIEW OF UN/LOCODE, 19 DECEMBER 2003 / SUBMITTED BY THE SECRETARIAT</title>
61
62
  <uri type="pdf">https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/pdf/G0430683.pdf?OpenElement</uri>
@@ -63,11 +64,23 @@ item.to_xml bibdata: true
63
64
  <docidentifier type="UN">TRADE/CEFACT/2004/32</docidentifier>
64
65
  <docnumber>TRADE/CEFACT/2004/32</docnumber>
65
66
  ...
66
- </bibdata>'
67
+ <ext>
68
+ <editorialgroup>
69
+ <committee>Committee on Trade</committee>
70
+ <committee>Centre for Trade Facilitation and Electronic Business</committee>
71
+ </editorialgroup>
72
+ <distribution>general</distribution>
73
+ <session>
74
+ <number>10</number>
75
+ <agenda-id>12</agenda-id>
76
+ </session>
77
+ <job_number>G0430683</job_number>
78
+ </ext>
79
+ </bibdata>"
67
80
  ----
68
81
 
69
82
  === Get code, and year
70
- [source]
83
+ [source,ruby]
71
84
  ----
72
85
  RelatonUn::UnBibliography.get "UN TRADE/CEFACT/2004/32"
73
86
  [relaton-un] ("UN TRADE/CEFACT/2004/32") fetching...
@@ -77,7 +90,7 @@ RelatonUn::UnBibliography.get "UN TRADE/CEFACT/2004/32"
77
90
  ----
78
91
 
79
92
  === Create bibliographic item from XML
80
- [source]
93
+ [source,ruby]
81
94
  ----
82
95
  RelatonUn::XMLParser.from_xml File.read('spec/fixtures/un_bib.xml')
83
96
  => #<RelatonUn::UnBibliographicItem:0x007fdc5e7ab678
@@ -85,7 +98,7 @@ RelatonUn::XMLParser.from_xml File.read('spec/fixtures/un_bib.xml')
85
98
  ----
86
99
 
87
100
  === Create bibliographic item from YAML
88
- [source]
101
+ [source,ruby]
89
102
  ----
90
103
  hash = YAML.load_file 'spec/fixtures/un_bib.yaml'
91
104
  => {"id"=>"TRADE/CEFACT/2004/32",
@@ -43,7 +43,9 @@
43
43
  <define name="xref">
44
44
  <element name="xref">
45
45
  <attribute name="target">
46
- <data type="IDREF"/>
46
+ <data type="string">
47
+ <param name="pattern">\i\c*|\c+#\c+</param>
48
+ </data>
47
49
  </attribute>
48
50
  <optional>
49
51
  <attribute name="type">
@@ -61,6 +63,11 @@
61
63
  </choice>
62
64
  </attribute>
63
65
  </optional>
66
+ <optional>
67
+ <attribute name="droploc">
68
+ <data type="boolean"/>
69
+ </attribute>
70
+ </optional>
64
71
  <text/>
65
72
  </element>
66
73
  </define>
@@ -578,6 +585,8 @@
578
585
  <ref name="ol"/>
579
586
  <ref name="dl"/>
580
587
  <ref name="formula"/>
588
+ <ref name="quote"/>
589
+ <ref name="sourcecode"/>
581
590
  </choice>
582
591
  </oneOrMore>
583
592
  </element>
@@ -661,6 +670,16 @@
661
670
  </choice>
662
671
  </attribute>
663
672
  </optional>
673
+ <optional>
674
+ <attribute name="valign">
675
+ <choice>
676
+ <value>top</value>
677
+ <value>middle</value>
678
+ <value>bottom</value>
679
+ <value>baseline</value>
680
+ </choice>
681
+ </attribute>
682
+ </optional>
664
683
  <choice>
665
684
  <zeroOrMore>
666
685
  <choice>
@@ -697,6 +716,16 @@
697
716
  </choice>
698
717
  </attribute>
699
718
  </optional>
719
+ <optional>
720
+ <attribute name="valign">
721
+ <choice>
722
+ <value>top</value>
723
+ <value>middle</value>
724
+ <value>bottom</value>
725
+ <value>baseline</value>
726
+ </choice>
727
+ </attribute>
728
+ </optional>
700
729
  <choice>
701
730
  <zeroOrMore>
702
731
  <choice>
@@ -834,6 +863,13 @@
834
863
  </define>
835
864
  <define name="standard-document">
836
865
  <element name="standard-document">
866
+ <attribute name="version"/>
867
+ <attribute name="type">
868
+ <choice>
869
+ <value>semantic</value>
870
+ <value>presentation</value>
871
+ </choice>
872
+ </attribute>
837
873
  <ref name="bibdata"/>
838
874
  <optional>
839
875
  <ref name="boilerplate"/>
@@ -855,7 +891,7 @@
855
891
  <oneOrMore>
856
892
  <choice>
857
893
  <ref name="content"/>
858
- <ref name="preface_abstract"/>
894
+ <ref name="abstract"/>
859
895
  <ref name="foreword"/>
860
896
  <ref name="introduction"/>
861
897
  <ref name="acknowledgements"/>
@@ -922,6 +958,9 @@
922
958
  <optional>
923
959
  <attribute name="script"/>
924
960
  </optional>
961
+ <optional>
962
+ <attribute name="type"/>
963
+ </optional>
925
964
  <optional>
926
965
  <attribute name="obligation">
927
966
  <choice>
@@ -961,9 +1000,6 @@
961
1000
  </define>
962
1001
  <define name="content-subsection">
963
1002
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
1003
  <ref name="Content-Section"/>
968
1004
  </element>
969
1005
  </define>
@@ -992,6 +1028,9 @@
992
1028
  </choice>
993
1029
  </attribute>
994
1030
  </optional>
1031
+ <optional>
1032
+ <attribute name="type"/>
1033
+ </optional>
995
1034
  <optional>
996
1035
  <ref name="section-title"/>
997
1036
  </optional>
@@ -1011,9 +1050,6 @@
1011
1050
  </define>
1012
1051
  <define name="clause">
1013
1052
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1053
  <ref name="Clause-Section"/>
1018
1054
  </element>
1019
1055
  </define>
@@ -1042,18 +1078,24 @@
1042
1078
  </choice>
1043
1079
  </attribute>
1044
1080
  </optional>
1081
+ <optional>
1082
+ <attribute name="type"/>
1083
+ </optional>
1045
1084
  <optional>
1046
1085
  <ref name="section-title"/>
1047
1086
  </optional>
1048
1087
  <group>
1049
- <group>
1050
- <zeroOrMore>
1051
- <ref name="BasicBlock"/>
1052
- </zeroOrMore>
1053
- <zeroOrMore>
1054
- <ref name="note"/>
1055
- </zeroOrMore>
1056
- </group>
1088
+ <choice>
1089
+ <group>
1090
+ <zeroOrMore>
1091
+ <ref name="BasicBlock"/>
1092
+ </zeroOrMore>
1093
+ <zeroOrMore>
1094
+ <ref name="note"/>
1095
+ </zeroOrMore>
1096
+ </group>
1097
+ <ref name="amend"/>
1098
+ </choice>
1057
1099
  <zeroOrMore>
1058
1100
  <choice>
1059
1101
  <ref name="clause-subsection"/>
@@ -1180,6 +1222,9 @@
1180
1222
  <optional>
1181
1223
  <attribute name="script"/>
1182
1224
  </optional>
1225
+ <optional>
1226
+ <attribute name="type"/>
1227
+ </optional>
1183
1228
  <optional>
1184
1229
  <attribute name="obligation">
1185
1230
  <choice>
@@ -1447,11 +1492,6 @@
1447
1492
  </optional>
1448
1493
  </element>
1449
1494
  </define>
1450
- <define name="preface_abstract">
1451
- <element name="abstract">
1452
- <ref name="Basic-Section"/>
1453
- </element>
1454
- </define>
1455
1495
  <define name="term-clause">
1456
1496
  <element name="clause">
1457
1497
  <optional>
@@ -1501,4 +1541,79 @@
1501
1541
  <ref name="CitationType"/>
1502
1542
  </element>
1503
1543
  </define>
1544
+ <define name="amend">
1545
+ <element name="amend">
1546
+ <optional>
1547
+ <attribute name="id">
1548
+ <data type="ID"/>
1549
+ </attribute>
1550
+ </optional>
1551
+ <attribute name="change">
1552
+ <choice>
1553
+ <value>add</value>
1554
+ <value>modify</value>
1555
+ <value>delete</value>
1556
+ </choice>
1557
+ </attribute>
1558
+ <optional>
1559
+ <attribute name="path"/>
1560
+ </optional>
1561
+ <optional>
1562
+ <attribute name="path_end"/>
1563
+ </optional>
1564
+ <optional>
1565
+ <attribute name="title"/>
1566
+ </optional>
1567
+ <optional>
1568
+ <element name="location">
1569
+ <zeroOrMore>
1570
+ <ref name="locality"/>
1571
+ </zeroOrMore>
1572
+ </element>
1573
+ </optional>
1574
+ <zeroOrMore>
1575
+ <ref name="autonumber"/>
1576
+ </zeroOrMore>
1577
+ <optional>
1578
+ <element name="description">
1579
+ <zeroOrMore>
1580
+ <ref name="BasicBlock"/>
1581
+ </zeroOrMore>
1582
+ </element>
1583
+ </optional>
1584
+ <optional>
1585
+ <element name="newcontent">
1586
+ <zeroOrMore>
1587
+ <ref name="BasicBlock"/>
1588
+ </zeroOrMore>
1589
+ </element>
1590
+ </optional>
1591
+ <optional>
1592
+ <element name="description">
1593
+ <zeroOrMore>
1594
+ <ref name="BasicBlock"/>
1595
+ </zeroOrMore>
1596
+ </element>
1597
+ </optional>
1598
+ </element>
1599
+ </define>
1600
+ <define name="autonumber">
1601
+ <element name="autonumber">
1602
+ <attribute name="type">
1603
+ <choice>
1604
+ <value>requirement</value>
1605
+ <value>recommendation</value>
1606
+ <value>permission</value>
1607
+ <value>table</value>
1608
+ <value>figure</value>
1609
+ <value>admonition</value>
1610
+ <value>formula</value>
1611
+ <value>sourcecode</value>
1612
+ <value>example</value>
1613
+ <value>note</value>
1614
+ </choice>
1615
+ </attribute>
1616
+ <text/>
1617
+ </element>
1618
+ </define>
1504
1619
  </grammar>
@@ -340,6 +340,13 @@
340
340
  </define>
341
341
  <define name="un-standard">
342
342
  <element name="un-standard">
343
+ <attribute name="version"/>
344
+ <attribute name="type">
345
+ <choice>
346
+ <value>semantic</value>
347
+ <value>presentation</value>
348
+ </choice>
349
+ </attribute>
343
350
  <ref name="bibdata"/>
344
351
  <optional>
345
352
  <ref name="boilerplate"/>
@@ -10,6 +10,11 @@ module RelatonUn
10
10
  @committee = committee
11
11
  end
12
12
 
13
+ # @return [true]
14
+ def presence?
15
+ true
16
+ end
17
+
13
18
  # @param builder [Nokogiri::XML::Builder]
14
19
  def to_xml(builder)
15
20
  builder.editorialgroup do |b|
@@ -21,5 +26,13 @@ module RelatonUn
21
26
  def to_hash
22
27
  single_element_array(committee.map { |c| { "committee" => c } })
23
28
  end
29
+
30
+ # @param prefix [String]
31
+ # @return [String]
32
+ def to_asciibib(prefix)
33
+ pref = prefix.empty? ? prefix : prefix + "."
34
+ pref += "editorialgroup"
35
+ committee.map { |c| "#{pref}.committee:: #{c}\n" }.join
36
+ end
24
37
  end
25
38
  end
@@ -9,6 +9,7 @@ module RelatonUn
9
9
  ret = super
10
10
  return if ret.nil?
11
11
 
12
+ ret[:submissionlanguage] = array ret[:submissionlanguage]
12
13
  session_hash_to_bib ret
13
14
  ret
14
15
  end
@@ -59,7 +59,7 @@ module RelatonUn
59
59
  # rubocop:disable Metrics/MethodLength
60
60
 
61
61
  # @return [RelatonUn::UnBibliographicItem]
62
- def un_bib_item
62
+ def un_bib_item # rubocop:disable Metrics/AbcSize
63
63
  UnBibliographicItem.new(
64
64
  type: "standard",
65
65
  fetched: Date.today.to_s,
@@ -75,6 +75,7 @@ module RelatonUn
75
75
  distribution: fetch_distribution,
76
76
  editorialgroup: fetch_editorialgroup,
77
77
  classification: fetch_classification,
78
+ job_number: hit[:job_number]
78
79
  )
79
80
  end
80
81
  # rubocop:enable Metrics/MethodLength
@@ -88,11 +89,6 @@ module RelatonUn
88
89
 
89
90
  # @return [Array<RelatonBib::TypedTitleString>]
90
91
  def fetch_title
91
- # fs = RelatonBib::FormattedString.new(
92
- # content: hit[:title], language: "en", script: "Latn",
93
- # )
94
- # [RelatonBib::TypedTitleString.new(type: "main", title: fs)]
95
- # [{ title_main: hit[:title], language: "en", script: "Latn" }]
96
92
  RelatonBib::TypedTitleString.from_string hit[:title], "en", "Latn"
97
93
  end
98
94
 
@@ -135,7 +131,7 @@ module RelatonUn
135
131
  def fetch_editorialgroup
136
132
  tc = hit[:ref].match(/^[\S]+/).to_s.split(/\/|-/).reduce([]) do |m, v|
137
133
  if BODY[v] then m << BODY[v]
138
- elsif v =~ /(AC|C|CN|CONF|GC|SC|Sub|WG).\d+|PC/ then m << v
134
+ elsif v.match? /(AC|C|CN|CONF|GC|SC|Sub|WG).\d+|PC/ then m << v
139
135
  else m
140
136
  end
141
137
  end.uniq
@@ -6,18 +6,23 @@ require "http-cookie"
6
6
  module RelatonUn
7
7
  # Page of hit collection.
8
8
  class HitCollection < RelatonBib::HitCollection
9
- AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) "\
10
- "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
9
+ AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) "\
10
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
11
11
  DOMAIN = "https://documents.un.org"
12
- BOUNDARY = "----WebKitFormBoundary6hkaBvITDck8dHCn"
12
+ BOUNDARY = "----WebKitFormBoundaryVarT9Z7AFUzw2lma"
13
13
 
14
14
  # @param text [String] reference to search
15
15
  def initialize(text)
16
16
  super
17
17
  @uri = URI.parse DOMAIN
18
18
  @jar = HTTP::CookieJar.new
19
- @http = Net::HTTP.new @uri.host, @uri.port
19
+ @http = Net::HTTP.new @uri.host, @uri.port # , "localhost", "8000"
20
20
  @http.use_ssl = true
21
+ # @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
22
+ # @http.cert_store = OpenSSL::X509::Store.new
23
+ # ca_file = "/Users/andrej/Library/Preferences/httptoolkit/ca.pem"
24
+ # @http.cert_store.set_default_paths
25
+ # @http.cert_store.add_file ca_file
21
26
  @http.read_timeout = 120
22
27
  if (form_resp = get_page)
23
28
  doc = Nokogiri::HTML page_resp(form_resp, text).body
@@ -48,19 +53,21 @@ module RelatonUn
48
53
  # @param form [Nokogiri::HTML::Document]
49
54
  # @param text [String]
50
55
  # @return [Array<String>]
51
- def form_data(form, text)
56
+ def form_data(form, text) # rubocop:disable Metrics/CyclomaticComplexity
52
57
  fd = form.xpath(
53
- "//input[@type!='radio']",
54
- "//input[@type='radio'][@checked]",
55
- "//select[@name!='view:_id1:_id2:cbLang']",
56
- "//textarea",
58
+ "//input[@type!='radio']|"\
59
+ "//input[@type='radio'][@checked]|"\
60
+ "//select[@name!='view:_id1:_id2:cbLang']|"\
61
+ "//textarea"
57
62
  ).reduce([]) do |m, i|
58
63
  v = case i[:name]
59
64
  when "view:_id1:_id2:txtSymbol" then text
65
+ when "view:_id1:_id2:rgTrunc" then "R"
60
66
  when "view:_id1:_id2:cbType" then "FP"
61
67
  when "view:_id1:_id2:cbSort" then "R"
62
68
  when "$$xspsubmitid" then "view:_id1:_id2:_id130"
63
- when "$$xspsubmitscroll" then "0|167"
69
+ when "$$xspsubmitscroll" then "0|102"
70
+ when "view:_id1" then "view:_id1"
64
71
  else i[:value]
65
72
  end
66
73
  m << %{--#{BOUNDARY}}
@@ -77,7 +84,7 @@ module RelatonUn
77
84
  form = Nokogiri::HTML form_resp.body
78
85
  req = Net::HTTP::Post.new form.at("//form")[:action]
79
86
  set_headers req
80
- req["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
87
+ req["Content-Type"] = "multipart/form-data; boundary=#{BOUNDARY}"
81
88
  req.body = form_data(form, text).join("\r\n")
82
89
  resp = @http.request req
83
90
  get_page URI.parse(resp["location"]).request_uri
@@ -91,7 +98,7 @@ module RelatonUn
91
98
 
92
99
  # @param item [Nokogiri::XML::Element]
93
100
  # @return [Hash]
94
- def hit_data(item)
101
+ def hit_data(item) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
95
102
  en = item.at("//span[.='ENGLISH']/../..")
96
103
  {
97
104
  ref: item.at("div/div/a")&.text&.sub("\u00A0", ""),
@@ -103,7 +110,8 @@ module RelatonUn
103
110
  link: link(en),
104
111
  session: session(item),
105
112
  agenda: agenda(item),
106
- distribution: distribution(item)
113
+ distribution: distribution(item),
114
+ job_number: job_number(item),
107
115
  }
108
116
  end
109
117
 
@@ -155,18 +163,25 @@ module RelatonUn
155
163
  item.at("//label[.='Distribution:']/following-sibling::span")&.text
156
164
  end
157
165
 
166
+ def job_number(item)
167
+ item.at("//span[contains(@id, 'cfJobNumE')]")&.text
168
+ end
169
+
158
170
  # rubocop:disable Metrics/MethodLength
159
171
 
160
172
  # @param req [Net::HTTP::Get, Net::HTTP::Post]
161
- def set_headers(req)
173
+ def set_headers(req) # rubocop:disable Metrics/AbcSize
162
174
  set_cookie req
163
175
  req["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,"\
164
- "image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
176
+ "image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;"\
177
+ "v=b3;q=0.9"
165
178
  req["Accept-Encoding"] = "gzip, deflate, br"
179
+ req["Accept-Language"] = "en-US;q=0.8,en;q=0.7"
166
180
  req["Cache-Control"] = "max-age=0"
167
181
  req["Connection"] = "keep-alive"
168
182
  req["Origin"] = "https://documents.un.org"
169
183
  req["Referer"] = "https://documents.un.org/prod/ods.nsf/home.xsp"
184
+ req["Sec-Fetch-Dest"] = "document"
170
185
  req["Sec-Fetch-Mode"] = "navigate"
171
186
  req["Sec-Fetch-Site"] = "same-origin"
172
187
  req["Sec-Fetch-User"] = "?1"
@@ -3,7 +3,7 @@ module RelatonUn
3
3
  include RelatonBib
4
4
 
5
5
  # @return [String, NilClass]
6
- attr_reader :session_number, :collaboration, :agenda_id, :item_footnote
6
+ attr_reader :session_number, :collaborator, :agenda_id, :item_footnote
7
7
 
8
8
  # @return [Date, NilClass]
9
9
  attr_reader :session_date
@@ -16,7 +16,7 @@ module RelatonUn
16
16
  # @param item_number [Array<String>]
17
17
  # @pqrqm item_name [Array<String>]
18
18
  # @pqrqm subitem_name [Array<String>]
19
- # @param collaboration [String]
19
+ # @param collaborator [String]
20
20
  # @param agenda_id [String]
21
21
  # @param item_footnote [String]
22
22
  def initialize(**args)
@@ -25,12 +25,12 @@ module RelatonUn
25
25
  @item_number = args.fetch(:item_number, [])
26
26
  @item_name = args.fetch(:item_name, [])
27
27
  @subitem_name = args.fetch(:subitem_name, [])
28
- @collaboration = args[:collaboration]
28
+ @collaborator = args[:collaborator]
29
29
  @agenda_id = args[:agenda_id]
30
30
  @item_footnote = args[:item_footnote]
31
31
  end
32
32
 
33
- # rubocop:disable Metrics/AbcSize
33
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
34
34
 
35
35
  # @param [Nokogiri::XML::Builder]
36
36
  def to_xml(builder)
@@ -40,26 +40,48 @@ module RelatonUn
40
40
  item_number.each { |n| b.send "item-number", n }
41
41
  item_name.each { |n| b.send "item-name", n }
42
42
  subitem_name.each { |n| b.send "subitem-name", n }
43
- b.collaboration collaboration if collaboration
43
+ b.collaborator collaborator if collaborator
44
44
  b.send "agenda-id", agenda_id if agenda_id
45
45
  b.send "item-footnote", item_footnote if item_footnote
46
46
  end
47
47
  end
48
48
 
49
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
49
+ # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength
50
50
  # @return [Hash]
51
51
  def to_hash
52
52
  hash = {}
53
53
  hash["session_number"] = session_number if session_number
54
54
  hash["session_date"] = session_date.to_s if session_date
55
- hash["item_number"] = single_element_array(item_number) if item_number.any?
55
+ if item_number.any?
56
+ hash["item_number"] = single_element_array(item_number)
57
+ end
56
58
  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
+ if subitem_name.any?
60
+ hash["subitem_name"] = single_element_array(subitem_name)
61
+ end
62
+ hash["collaborator"] = collaborator if collaborator
59
63
  hash["agenda_id"] = agenda_id if agenda_id
60
64
  hash["item_footnote"] = item_footnote if item_footnote
61
65
  hash
62
66
  end
63
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
67
+ # rubocop:enable Metrics/PerceivedComplexity
68
+
69
+ # @param prefix [String]
70
+ # @return [String]
71
+ def to_asciibib(prefix = "")
72
+ pref = prefix.empty? ? prefix : prefix + "."
73
+ pref += "session"
74
+ out = ""
75
+ out += "#{pref}.session_number:: #{session_number}\n" if session_number
76
+ out += "#{pref}.session_date:: #{session_date}\n" if session_date
77
+ item_number.each { |n| out += "#{pref}.item_number:: #{n}\n" }
78
+ item_name.each { |n| out += "#{pref}.item_name:: #{n}\n" }
79
+ subitem_name.each { |n| out += "#{pref}.subitem_name:: #{n}\n" }
80
+ out += "#{pref}.collaborator:: #{collaborator}\n" if collaborator
81
+ out += "#{pref}.agenda_id:: #{agenda_id}\n" if agenda_id
82
+ out += "#{pref}.item_footnote:: #{item_footnote}\n" if item_footnote
83
+ out
84
+ end
85
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
64
86
  end
65
87
  end
@@ -1,5 +1,7 @@
1
1
  module RelatonUn
2
2
  class UnBibliographicItem < RelatonBib::BibliographicItem
3
+ include RelatonBib
4
+
3
5
  TYPES = %w[
4
6
  recommendation plenary addendum communication corrigendum reissue agenda
5
7
  budgetary sec-gen-notes expert-report resolution
@@ -12,37 +14,69 @@ module RelatonUn
12
14
  attr_reader :session
13
15
 
14
16
  # @return [String, NilClass]
15
- attr_reader :distribution
17
+ attr_reader :distribution, :job_number
18
+
19
+ # @return [Array<String>]
20
+ attr_reader :submissionlanguage
16
21
 
17
22
  # @param session [RelatonUn::Session, NilClass]
18
- # @param distribution [String]
23
+ # @param distribution [String, nil]
24
+ # @param job_number [String, nil]
19
25
  def initialize(**args)
20
26
  if args[:distribution] && !DISTRIBUTIONS.has_value?(args[:distribution])
21
- warn "[relaton-un] WARNING: invalid distribution: #{args[:distribution]}"
27
+ warn "[relaton-un] WARNING: invalid distribution: "\
28
+ "#{args[:distribution]}"
22
29
  end
30
+ @submissionlanguage = args.delete :submissionlanguage
23
31
  @distribution = args.delete :distribution
24
32
  @session = args.delete :session
33
+ @job_number = args.delete :job_number
25
34
  super **args
26
- # @doctype = args[:doctype]
27
35
  end
28
36
 
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|
37
+ # @param opts [Hash]
38
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
39
+ # @option opts [Boolean] :bibdata
40
+ # @option opts [String] :lang language
41
+ # @return [String] XML
42
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
43
+ super **opts do |b|
33
44
  b.ext do
45
+ b.doctype doctype if doctype
46
+ submissionlanguage&.each { |sl| b.submissionlanguage sl }
34
47
  editorialgroup&.to_xml b
48
+ ics&.each { |i| i.to_xml b }
35
49
  b.distribution distribution if distribution
36
50
  session&.to_xml b if session
51
+ b.job_number job_number if job_number
37
52
  end
38
53
  end
39
54
  end
40
55
 
41
56
  # @return [Hash]
42
- def to_hash
57
+ def to_hash # rubocop:disable Metrics/AbcSize
43
58
  hash = super
59
+ if submissionlanguage&.any?
60
+ hash["submissionlanguage"] = single_element_array submissionlanguage
61
+ end
62
+ hash["distribution"] = distribution if distribution
44
63
  hash["session"] = session.to_hash if session
64
+ hash["job_number"] = job_number if job_number
45
65
  hash
46
66
  end
67
+
68
+ # @param prefix [String]
69
+ # @return [String]
70
+ def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize
71
+ pref = prefix.empty? ? prefix : prefix + "."
72
+ out = super
73
+ submissionlanguage.each do |sl|
74
+ out += "#{pref}submissionlanguage:: #{sl}\n"
75
+ end
76
+ out += "#{pref}distribution:: #{distribution}\n" if distribution
77
+ out += session.to_asciibib prefix if session
78
+ out += "#{pref}job_number:: #{job_number}\n" if job_number
79
+ out
80
+ end
47
81
  end
48
82
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonUn
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.5.0".freeze
3
3
  end
@@ -13,28 +13,31 @@ module RelatonUn
13
13
  # @return [Hash]
14
14
  def item_data(item)
15
15
  data = super
16
- data[:session] = fetch_session item
17
- data[:distribution] = item.at("distribution")&.text
16
+ ext = item.at "./ext"
17
+ return data unless ext
18
+
19
+ data[:submissionlanguage] = fetch_submissionlanguage ext
20
+ data[:session] = fetch_session ext
21
+ data[:distribution] = ext.at("distribution")&.text
22
+ data[:job_number] = ext.at("job_number")&.text
18
23
  data
19
24
  end
20
25
 
21
26
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
22
27
 
23
- # @param item [Nokogiri::XML::Element]
28
+ # @param ext [Nokogiri::XML::Element]
24
29
  # @return [RelatonUn::Session]
25
- def fetch_session(item)
26
- session = item.at "./ext/session"
27
- return unless session
28
-
30
+ def fetch_session(ext) # rubocop:disable Metrics/CyclomaticComplexity
31
+ session = ext.at "./session"
29
32
  RelatonUn::Session.new(
30
33
  session_number: session.at("number")&.text,
31
34
  session_date: session.at("session-date")&.text,
32
35
  item_number: session.xpath("item-number").map(&:text),
33
36
  item_name: session.xpath("item-name").map(&:text),
34
37
  subitem_name: session.xpath("subitem-name").map(&:text),
35
- collaboration: session.at("collaboration")&.text,
38
+ collaborator: session.at("collaborator")&.text,
36
39
  agenda_id: session.at("agenda-id")&.text,
37
- item_footnote: session.at("item-footnote")&.text,
40
+ item_footnote: session.at("item-footnote")&.text
38
41
  )
39
42
  end
40
43
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -45,9 +48,15 @@ module RelatonUn
45
48
  eg = ext.at("./editorialgroup")
46
49
  return unless eg
47
50
 
48
- committee = eg&.xpath("committee")&.map &:text
51
+ committee = eg.xpath("committee").map &:text
49
52
  EditorialGroup.new committee
50
53
  end
54
+
55
+ # @param ext [Nokogiri::XML::Element]
56
+ # @return [Array<String>]
57
+ def fetch_submissionlanguage(ext)
58
+ ext.xpath("./submissionlanguage").map(&:text)
59
+ end
51
60
  end
52
61
  end
53
62
  end
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
43
43
 
44
44
  spec.add_dependency "faraday"
45
45
  spec.add_dependency "http-cookie"
46
- spec.add_dependency "relaton-bib", "~> 1.2.0"
46
+ spec.add_dependency "relaton-bib", "~> 1.5.0"
47
47
  spec.add_dependency "unf_ext", ">= 0.0.7.7"
48
48
  end
49
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: 1.2.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-10-09 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: 1.2.0
159
+ version: 1.5.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: 1.2.0
166
+ version: 1.5.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: unf_ext
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -223,7 +223,7 @@ licenses:
223
223
  metadata:
224
224
  homepage_uri: https://github.com/relaton/relaton-un
225
225
  source_code_uri: https://github.com/relaton/relaton-un
226
- post_install_message:
226
+ post_install_message:
227
227
  rdoc_options: []
228
228
  require_paths:
229
229
  - lib
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  requirements: []
241
241
  rubygems_version: 3.0.6
242
- signing_key:
242
+ signing_key:
243
243
  specification_version: 4
244
244
  summary: 'RelatonIso: retrieve CC Standards for bibliographic use using the IsoBibliographicItem
245
245
  model'