relaton-iso 1.1.0 → 1.5.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23dbce13e2b3ded9fbcca9cc7c9193fdf8bdec270fdf52b416652f334f8af593
4
- data.tar.gz: bb3482b113d31b79c7050f0d2206cb3df3588f8ef1cc45e72721c9c2dfd50201
3
+ metadata.gz: 0e719a41c79adcfe2abe6077cd01eadc0a45486d41ec4d1569603174fae16f6e
4
+ data.tar.gz: f2f8027f2988c5bec982f49b19fb0d53e92ded9c81dc3eae2f9e3f0976418da7
5
5
  SHA512:
6
- metadata.gz: a9bfbe60c42fb0ee0aee1e67c4b125715d3cad5ec9b52dfa87b1efb2484260ba768da03aabddc4794d28c2d18a840dc9f982eb28b1e41399f3166052806294d8
7
- data.tar.gz: dd40529ac753e12996e0fc57abcf8b1bfa161059f726688ab0895f921cc8d65d3b6f224eb39a51081137b2338e0e891cc042d6cd470e2aa38195e53970bf6d63
6
+ metadata.gz: 35ba3e6b301f5daabfa60c7bf4a5a41b8eb39914ad4e7a963e4cb9038cd9bdbbc1bf9080f2f0eb1f2ffafa0e54d00205ced6ebbb7d80f6ec39b1dbd9dbfb325b
7
+ data.tar.gz: 963fb3f2dc634534739e2db773fc626552e9346d70a9002c78a5a6b1ccac517f2de96cc2e2986b09768bb9707845219531e4ce98625b82ca377715e9a12346b3
@@ -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
@@ -35,26 +35,28 @@ Or install it yourself as:
35
35
 
36
36
  [source,ruby]
37
37
  ----
38
- hit_pages = RelatonIso::IsoBibliography.search("19115")
39
- => [[<RelatonIso::Hit:0x007f9a049df0d0 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO 19115-2:2019 Geographic information -- Metadata -- Part 2: Extensions for acquisition and processing">,
40
- <RelatonIso::Hit:0x007f9a049df0a8 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO 19115-1:2014 Geographic information -- Metadata -- Part 1: Fundamentals">,
41
- ...
42
- <RelatonIso::Hit:0x007f9a049deec8 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO/TS 19157-2:2016 Geographic information -- Data quality -- Part 2: XML schema implementation">]]
38
+ require 'relaton_iso'
39
+ => true
40
+
41
+ hit_collection = RelatonIso::IsoBibliography.search("ISO 19115")
42
+ => <RelatonIso::HitCollection:0x007fa5bc847038 @ref=19115 @fetched=false>
43
43
 
44
- hit_collection = hit_pages.first
45
- => [<RelatonIso::Hit:0x007f9a049df0d0 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO 19115-2:2019 Geographic information -- Metadata -- Part 2: Extensions for acquisition and processing">,
46
- <RelatonIso::Hit:0x007f9a049df0a8 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO 19115-1:2014 Geographic information -- Metadata -- Part 1: Fundamentals">,
47
- ...
48
- <RelatonIso::Hit:0x007f9a049deef0 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO/TS 19139-2:2012 Geographic information -- Metadata -- XML schema implementation -- Part 2: Extensions for imagery and gridded data">,
49
- <RelatonIso::Hit:0x007f9a049deec8 @text="19115" @fullIdentifier="" @matchedWords=["19115"] @category="standard" @title="ISO/TS 19157-2:2016 Geographic information -- Data quality -- Part 2: XML schema implementation">]
44
+ hit_collection.first
45
+ => <RelatonIso::Hit:0x007f87e71ea9f8 @text="ISO 19115" @fetched="false" @fullIdentifier="" @title="">
50
46
 
51
- item = hit_collection[1].fetch
52
- => #<RelatonIsoBib::IsoBibliographicItem:0x007f9a030a9d90
47
+ item = hit_collection[2].fetch
48
+ => #<RelatonIsoBib::IsoBibliographicItem:0x007fa5dca89510
53
49
  @abstract=
54
- [#<RelatonBib::FormattedString:0x007f9a030a2518
50
+ [#<RelatonBib::FormattedString:0x007fa5dca88458
55
51
  @content=
56
- "ISO 19115-1:2014 defines the schema required for describing geographic information and services by means of metadata. It provides information about the identification, the
57
- ...
52
+ "ISO/TS 19115-3:2016 defines an integrated XML implementation of ISO 19115‑1, ..."
53
+
54
+ item.docidentifier
55
+ => [#<RelatonBib::DocumentIdentifier:0x007fd9ce9c6878 @id="ISO/TS 19115-3:2016", @scope=nil, @type="ISO">,
56
+ #<RelatonBib::DocumentIdentifier:0x007fd9ce9c6350 @id="urn:iso:std:iso-ts:ts:19115:-3:stage-90.92:ed-1:en,fr", @scope=nil, @type="URN">]
57
+
58
+ item.docidentifier.detect { |di| di.type == "URN" }.id
59
+ => "urn:iso:std:iso-ts:ts:19115:-3:stage-90.92:ed-1:en,fr"
58
60
  ----
59
61
 
60
62
  === XML serialization
@@ -67,79 +69,38 @@ Possible options:
67
69
  [source,ruby]
68
70
  ----
69
71
  item.to_xml
70
- =>"<bibitem id="ISO19115-1-2014">
71
- <title type="title-main" format="text/plain" language="en" script="Latn">Metadata</title>
72
+ "<bibitem id="ISO/TS19115-3-2016" type="standard">
73
+ <fetched>2020-09-11</fetched>
72
74
  <title type="title-intro" format="text/plain" language="en" script="Latn">Geographic information</title>
73
- <title type="title-part" format="text/plain" language="en" script="Latn">Part 1: Fundamentals</title>
74
- <title type="main" format="text/plain" language="en" script="Latn">Metadata - Geographic information - Part 1: Fundamentals</title>
75
- <title type="title-main" format="text/plain" language="fr" script="Latn">Métadonnées</title>
75
+ <title type="title-main" format="text/plain" language="en" script="Latn"> Metadata</title>
76
+ <title type="title-part" format="text/plain" language="en" script="Latn">Part 3: XML schema implementation for fundamental concepts</title>
77
+ <title type="main" format="text/plain" language="en" script="Latn">Geographic information - Metadata - Part 3: XML schema implementation for fundamental concepts</title>
76
78
  <title type="title-intro" format="text/plain" language="fr" script="Latn">Information géographique</title>
77
- <title type="title-part" format="text/plain" language="fr" script="Latn">Partie 1: Principes de base</title>
78
- <title type="main" format="text/plain" language="fr" script="Latn">Métadonnées - Information géographique - Partie 1: Principes de base</title>
79
- <uri type="src">https://www.iso.org/standard/53798.html</uri>
80
- <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:53798:en</uri>
81
- <uri type="rss">https://www.iso.org/contents/data/standard/05/37/53798.detail.rss</uri>
82
- <docidentifier type="ISO">ISO 19115-1:2014</docidentifier>
83
- <date type="published">
84
- <on>2014</on>
85
- </date>
86
- <contributor>
87
- <role type="publisher"/>
88
- <organization>
89
- <name>International Organization for Standardization</name>
90
- <abbreviation>ISO</abbreviation>
91
- <uri>www.iso.org</uri>
92
- </organization>
93
- </contributor>
94
- <edition>1</edition>
95
- <language>en</language>
96
- <language>fr</language>
97
- <script>Latn</script>
98
- <abstract format="text/plain" language="en" script="Latn">ISO 19115-1:2014 defines the schema required for describing geographic information and services by means of metadata. It provides information about the identification, the extent, the quality, the spatial and temporal aspects, the content, the spatial reference, the portrayal, distribution, and other properties of digital geographic data and services.ISO 19115-1:2014 is applicable to:-the cataloguing of all types of resources, clearinghouse activities, and the full description of datasets and services;-geographic services, geographic datasets, dataset series, and individual geographic features and feature properties.ISO 19115-1:2014 defines:-mandatory and conditional metadata sections, metadata entities, and metadata elements;-the minimum set of metadata required to serve most metadata applications (data discovery, determining data fitness for use, data access, data transfer, and use of digital data and services);-optional metadata elements to allow for a more extensive standard description of resources, if required;-a method for extending metadata to fit specialized needs.Though ISO 19115-1:2014 is applicable to digital data and services, its principles can be extended to many other types of resources such as maps, charts, and textual documents as well as non-geographic data. Certain conditional metadata elements might not apply to these other forms of data.</abstract>
99
- <abstract format="text/plain" language="fr" script="Latn">L'ISO 19115-1:2014 définit le schéma requis pour décrire des informations géographiques et des services au moyen de métadonnées. Elle fournit des informations concernant l'identification, l'étendue, la qualité, les aspects spatiaux et temporels, le contenu, la référence spatiale, la représentation des données, la distribution et d'autres propriétés des données géographiques numériques et des services.L'ISO 19115-1:2014 est applicable:-au catalogage de tous les types de ressources, des activités des centres d'informations et à la description complète des jeux de données et des services,-aux services géographiques, jeux de données géographiques, séries de jeux de données, entités géographiques individuelles et propriétés d'entités.L'ISO 19115-1:2014 définit:-des sections relatives aux métadonnées obligatoires et facultatives, aux entités de métadonnées et aux éléments de métadonnées,-le jeu minimal de métadonnées requis pour répondre au besoin de la plupart des applications des métadonnées (la découverte des données, la détermination de l'adéquation des données à une utilisation, l'accès aux données, le transfert des données et l'utilisation des données numériques et des services),-les éléments de métadonnées facultatifs pour permettre une description standard plus poussée des ressources, si cela est nécessaire,-un procédé d'extension des métadonnées pour s'adapter aux besoins spéciaux.L'ISO 19115-1:2014 est applicable aux données numériques et services, ses principes peuvent être étendus à bien d'autres types de ressources telles que les cartes, les graphes et les documents textes, de même qu'à des données non géographiques. Certains éléments de métadonnées conditionnels peuvent ne pas s'appliquer à ces autres formes de données.</abstract>
100
- <status>
101
- <stage>90</stage>
102
- <substage>20</substage>
103
- </status>
104
- <copyright>
105
- <from>2014</from>
106
- <owner>
107
- <organization>
108
- <name>ISO</name>
109
- </organization>
110
- </owner>
111
- </copyright>
112
- <relation type="obsoletes">
113
- <bibitem>
114
- <formattedref format="text/plain">ISO 19115:2003</formattedref>
115
- </bibitem>
116
- </relation>
117
- <relation type="obsoletes">
118
- <bibitem>
119
- <formattedref format="text/plain">ISO 19115:2003/Cor 1:2006</formattedref>
120
- </bibitem>
121
- </relation>
122
- <relation type="updates">
123
- <bibitem>
124
- <formattedref format="text/plain">ISO 19115-1:2014/Amd 1:2018</formattedref>
125
- </bibitem>
126
- </relation>
79
+ <title type="title-main" format="text/plain" language="fr" script="Latn">Métadonnées</title>
80
+ <title type="title-part" format="text/plain" language="fr" script="Latn">Partie 3: Mise en oeuvre par des schémas XML</title>
81
+ <title type="main" format="text/plain" language="fr" script="Latn">Information géographique - Métadonnées - Partie 3: Mise en oeuvre par des schémas XML</title>
82
+ <uri type="src">https://www.iso.org/standard/32579.html</uri>
83
+ <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:32579:en</uri>
84
+ <uri type="rss">https://www.iso.org/contents/data/standard/03/25/32579.detail.rss</uri>
85
+ <docidentifier type="ISO">ISO/TS 19115-3:2016</docidentifier>
86
+ <docidentifier type="URN">urn:iso:std:iso-ts:ts:19115:-3:stage-90.92:ed-1:en,fr</docidentifier>
87
+ ...
127
88
  </bibitem>"
128
89
 
129
90
  item.to_xml bibdata: true
130
- =>"<bibdata>
91
+ =>"<bibdata type="standard">
131
92
  ...
132
93
  <ext>
133
- <doctype>international-standard</doctype>
94
+ <doctype>technical-specification</doctype>
134
95
  <editorialgroup>
135
- <technical_committee number="211" type="TC">ISO/TC 211Geographic information/Geomatics</technical_committee>
96
+ <technical-committee number="211" type="TC">ISO/TC 211Geographic information/Geomatics</technical-committee>
136
97
  </editorialgroup>
137
98
  <ics>
138
99
  <code>35.240.70</code>
139
100
  <text>IT applications in science</text>
140
101
  </ics>
141
102
  <structuredidentifier type="ISO">
142
- <project-number>ISO 19115</project-number>
103
+ <project-number>ISO/TS 19115</project-number>
143
104
  </structuredidentifier>
144
105
  </ext>
145
106
  </bibdata>"
@@ -152,65 +113,55 @@ item.to_xml note: [{ text: "Note", type: "note" }]
152
113
  </bibitem>"
153
114
  ----
154
115
 
155
- === Get serialisation in response to code, year, and options
116
+ === Get specific language
156
117
 
157
118
  [source,ruby]
158
119
  ----
159
- RelatonIso::IsoBibliography.get('ISO 19115', "2014", {all_parts: true}).title
160
- => [#<RelatonIsoBib::TypedTitleString:0x007f9a05a1dcd0
161
- @title=#<RelatonBib::FormattedString:0x007f9a05a1d668 @content="Metadata", @format="text/plain", @language=["en"], @script=["Latn"]>,
162
- @type="title-main">,
163
- #<RelatonIsoBib::TypedTitleString:0x007f9a05a1d1b8
164
- @title=#<RelatonBib::FormattedString:0x007f9a05a1c970 @content="Geographic information", @format="text/plain", @language=["en"], @script=["Latn"]>,
120
+ item.title lang: 'en'
121
+ => [#<RelatonBib::TypedTitleString:0x007fd9aedcf390
122
+ @title=#<RelatonBib::FormattedString:0x007fd9aedcf250 @content="Geographic information", @format="text/plain", @language=["en"], @script=["Latn"]>,
165
123
  @type="title-intro">,
166
- #<RelatonIsoBib::TypedTitleString:0x007f9a030d38c0
167
- @title=
168
- #<RelatonBib::FormattedString:0x007f9a030d3320 @content="Metadata - Geographic information - Part 1: Fundamentals", @format="text/plain", @language=["en"], @script=["Latn"]>,
169
- @type="main">,
170
- #<RelatonIsoBib::TypedTitleString:0x007f9a030d26a0
171
- @title=#<RelatonBib::FormattedString:0x007f9a030d21f0 @content="Métadonnées", @format="text/plain", @language=["fr"], @script=["Latn"]>,
124
+ #<RelatonBib::TypedTitleString:0x007fd9aedcf188
125
+ @title=#<RelatonBib::FormattedString:0x007fd9aedcf048 @content=" Metadata", @format="text/plain", @language=["en"], @script=["Latn"]>,
172
126
  @type="title-main">,
173
- #<RelatonIsoBib::TypedTitleString:0x007f9a030d1d68
174
- @title=#<RelatonBib::FormattedString:0x007f9a030d15e8 @content="Information géographique", @format="text/plain", @language=["fr"], @script=["Latn"]>,
127
+ #<RelatonBib::TypedTitleString:0x007fd9aedcef80
128
+ @title=#<RelatonBib::FormattedString:0x007fd9aedcee40 @content="Part 3: XML schema implementation for fundamental concepts", @format="text/plain", @language=["en"], @script=["Latn"]>,
129
+ @type="title-part">,
130
+ #<RelatonBib::TypedTitleString:0x007fd9aedcecb0
131
+ @title=
132
+ #<RelatonBib::FormattedString:0x007fd9aedceb70
133
+ @content="Geographic information - Metadata - Part 3: XML schema implementation for fundamental concepts",
134
+ @format="text/plain",
135
+ @language=["en"],
136
+ @script=["Latn"]>,
137
+ @type="main">]
138
+
139
+ item.title lang: 'fr'
140
+ => [#<RelatonBib::TypedTitleString:0x007fd9ce9c7890
141
+ @title=#<RelatonBib::FormattedString:0x007fd9ce9c7750 @content="Information géographique", @format="text/plain", @language=["fr"], @script=["Latn"]>,
175
142
  @type="title-intro">,
176
- #<RelatonIsoBib::TypedTitleString:0x007f9a030d0a80
143
+ #<RelatonBib::TypedTitleString:0x007fd9ce9c7688
144
+ @title=#<RelatonBib::FormattedString:0x007fd9ce9c7548 @content="Métadonnées", @format="text/plain", @language=["fr"], @script=["Latn"]>,
145
+ @type="title-main">,
146
+ #<RelatonBib::TypedTitleString:0x007fd9ce9c7480
147
+ @title=#<RelatonBib::FormattedString:0x007fd9ce9c7340 @content="Partie 3: Mise en oeuvre par des schémas XML", @format="text/plain", @language=["fr"], @script=["Latn"]>,
148
+ @type="title-part">,
149
+ #<RelatonBib::TypedTitleString:0x007fd9ce9c71b0
177
150
  @title=
178
- #<RelatonBib::FormattedString:0x007f9a030d0530
179
- @content="Métadonnées - Information géographique - Partie 1: Principes de base",
151
+ #<RelatonBib::FormattedString:0x007fd9ce9c7070
152
+ @content="Information géographique - Métadonnées - Partie 3: Mise en oeuvre par des schémas XML",
180
153
  @format="text/plain",
181
154
  @language=["fr"],
182
155
  @script=["Latn"]>,
183
156
  @type="main">]
184
- ----
185
-
186
- === Get specific language
187
157
 
188
- [source,ruby]
189
- ----
190
- item = RelatonIso::IsoBibliography.get 'ISO 19115', nil, {lang: "en"}
191
- item.to_xml
192
- => <bibitem id="ISO19115-1-2014" type="standard">
193
- <fetched>2020-01-22</fetched>
194
- <title type="title-intro" format="text/plain" language="en" script="Latn">Geographic information</title>
195
- <title type="title-main" format="text/plain" language="en" script="Latn">Metadata</title>
196
- <title type="main" format="text/plain" language="en" script="Latn">Geographic information – Metadata</title>
197
- <uri type=\"src\">https://www.iso.org/standard/53798.html</uri>
198
- ...
199
- </bibitem>
200
-
201
- item = RelatonIso::IsoBibliography.get 'ISO 19115', nil, {lang: "fr"}
202
- item.to_xml
203
- => <bibitem id="ISO19115-1-2014" type="standard">
204
- <fetched>2020-01-22</fetched>
205
- <title type="title-intro" format="text/plain" language="en" script="Latn">Geographic information</title>
206
- <title type="title-main" format="text/plain" language="en" script="Latn">Metadata</title>
207
- <title type="main" format="text/plain" language="en" script="Latn">Geographic information – Metadata</title>
208
- <title type="title-intro" format="text/plain" language="fr" script="Latn">Information géographique</title>
209
- <title type="title-main" format="text/plain" language="fr" script="Latn">Métadonnées</title>
210
- <title type="main" format="text/plain" language="fr" script="Latn">Information géographique – Métadonnées</title>
211
- <uri type="src">https://www.iso.org/standard/53798.html</uri>
212
- ...
213
- </bibitem>
158
+ item.abstract lang: 'en'
159
+ => #<RelatonBib::FormattedString:0x007fd9ce9d9bd0
160
+ @content=
161
+ "ISO/TS 19115-3:2016 defines an integrated XML implementation of ISO 19115‑1, ISO 19115‑2, and concepts ..."
162
+ @format="text/plain",
163
+ @language=["en"],
164
+ @script=["Latn"]>
214
165
  ----
215
166
 
216
167
  == Development
@@ -38,9 +38,10 @@ module RelatonIso
38
38
 
39
39
  if year.nil?
40
40
  /^(?<code1>[^\s]+(\s\w+)?\s[\d-]+)(:(?<year1>\d{4}))?(?<code2>\s\w+)?/ =~ code
41
+ /:(?<year2>\d{4})/ =~ corr
41
42
  unless code1.nil?
42
43
  code = code1 + code2.to_s
43
- year = year1
44
+ year = year2 || year1
44
45
  end
45
46
  end
46
47
  opts[:all_parts] ||= code !~ %r{^[^\s]+\s\d+-\d+} && opts[:all_parts].nil? && code2.nil?
@@ -145,7 +146,7 @@ module RelatonIso
145
146
  def isobib_results_filter(result, year, opts)
146
147
  missed_years = []
147
148
  hits = result.reduce!([]) do |hts, h|
148
- if !year || %r{:(?<iyear>\d{4})} =~ h.hit["docRef"] && iyear == year
149
+ if !year || %r{:(?<iyear>\d{4})(?!.*:\d{4})} =~ h.hit["docRef"] && iyear == year
149
150
  hts << h
150
151
  else
151
152
  missed_years << iyear
@@ -54,20 +54,20 @@ module RelatonIso
54
54
  # @param hit_data [Hash]
55
55
  # @param lang [String, NilClass]
56
56
  # @return [Hash]
57
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
58
- def parse_page(hit_data, lang = nil)
59
- path = "/contents/data/standard#{hit_data["splitPath"]}/#{hit_data["csnumber"]}.html"
57
+ def parse_page(hit_data, lang = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
58
+ path = "/contents/data/standard#{hit_data['splitPath']}/"\
59
+ "#{hit_data['csnumber']}.html"
60
60
  doc, url = get_page path
61
61
 
62
62
  # Fetch edition.
63
- edition = doc&.xpath("//strong[contains(text(), 'Edition')]/..")&.
64
- children&.last&.text&.match(/\d+/)&.to_s
63
+ edition = doc&.xpath("//strong[contains(text(), 'Edition')]/..")
64
+ &.children&.last&.text&.match(/\d+/)&.to_s
65
65
 
66
66
  titles, abstract, langs = fetch_titles_abstract(doc, lang)
67
67
 
68
68
  RelatonIsoBib::IsoBibliographicItem.new(
69
69
  fetched: Date.today.to_s,
70
- docid: fetch_docid(hit_data["docRef"]),
70
+ docid: fetch_docid(hit_data, langs),
71
71
  docnumber: fetch_docnumber(doc),
72
72
  edition: edition,
73
73
  language: langs.map { |l| l[:lang] },
@@ -84,10 +84,9 @@ module RelatonIso
84
84
  link: fetch_link(doc, url),
85
85
  relation: fetch_relations(doc),
86
86
  place: ["Geneva"],
87
- structuredidentifier: fetch_structuredidentifier(doc),
87
+ structuredidentifier: fetch_structuredidentifier(doc)
88
88
  )
89
89
  end
90
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
91
90
 
92
91
  private
93
92
 
@@ -97,14 +96,15 @@ module RelatonIso
97
96
  # @return [Array<Array>]
98
97
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
99
98
  def fetch_titles_abstract(doc, lang)
100
- titles = []
99
+ titles = RelatonBib::TypedTitleStringCollection.new
101
100
  abstract = []
102
101
  langs = languages(doc, lang).reduce([]) do |s, l|
103
102
  # Don't need to get page for en. We already have it.
104
103
  d = l[:path] ? get_page(l[:path])[0] : doc
105
- unless d.at("//h5[@class='help-block'][.='недоступно на русском языке']")
104
+ unless d.at("//h5[@class='help-block']"\
105
+ "[.='недоступно на русском языке']")
106
106
  s << l
107
- titles << fetch_title(d, l[:lang])
107
+ titles += fetch_title(d, l[:lang])
108
108
 
109
109
  # Fetch abstracts.
110
110
  abstract_content = d.css("div[itemprop='description'] p").text
@@ -160,18 +160,42 @@ module RelatonIso
160
160
  n += 1
161
161
  end
162
162
  [Nokogiri::HTML(resp.body), url]
163
- rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
164
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
165
- OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
163
+ rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
164
+ EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
165
+ Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
166
166
  raise RelatonBib::RequestError, "Could not access #{url}"
167
167
  end
168
168
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
169
169
 
170
170
  # Fetch docid.
171
- # @param doc [Nokogiri::HTML::Document]
171
+ # @param hit [Hash]
172
+ # @param langs [Array<Hash>]
172
173
  # @return [Array<RelatonBib::DocumentIdentifier>]
173
- def fetch_docid(doc_ref)
174
- [RelatonBib::DocumentIdentifier.new(id: doc_ref, type: "ISO")]
174
+ def fetch_docid(hit, langs)
175
+ [
176
+ RelatonBib::DocumentIdentifier.new(id: hit["docRef"], type: "ISO"),
177
+ RelatonBib::DocumentIdentifier.new(id: fetch_urn(hit, langs),
178
+ type: "URN"),
179
+ ]
180
+ end
181
+
182
+ # @param hit [Hash]
183
+ # @param langs [Array<Hash>]
184
+ # @returnt [String]
185
+ def fetch_urn(hit, langs) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
186
+ orig = hit["docRef"].split(" ").first.downcase.split("/").join "-"
187
+ %r{(?<=)(?<type>DATA|GUIDE|ISP|IWA|PAS|R|TR|TS|TTA)} =~ hit["docRef"]
188
+ urn = "urn:iso:std:#{orig}"
189
+ urn += ":#{type.downcase}" if type
190
+ urn += ":#{hit['docNumber']}"
191
+ urn += ":-#{hit['docPart']}" if hit["docPart"] && !hit["docPart"].empty?
192
+ urn += ":stage-#{hit['stageId']}"
193
+ urn += ":ed-#{hit['docEdition']}" if hit["docEdition"]
194
+ if hit["docElem"] && !hit["docElem"].empty? && hit["docElem"] != "0"
195
+ urn += ":#{hit['docElem'].downcase}:#{hit['docElemSeq']}"
196
+ end
197
+ urn += ":" + langs.map { |l| l[:lang] }.join(",")
198
+ urn
175
199
  end
176
200
 
177
201
  def fetch_docnumber(doc)
@@ -180,11 +204,11 @@ module RelatonIso
180
204
  end
181
205
 
182
206
  # @param doc [Nokogiri::HTML::Document]
183
- def fetch_structuredidentifier(doc)
207
+ def fetch_structuredidentifier(doc) # rubocop:disable Metrics/MethodLength
184
208
  item_ref = doc.at("//nav[contains(@class, 'heading-condensed')]/h1")
185
209
  unless item_ref
186
210
  return RelatonIsoBib::StructuredIdentifier.new(
187
- project_number: "?", part_number: "", prefix: nil, id: "?",
211
+ project_number: "?", part_number: "", prefix: nil, id: "?"
188
212
  )
189
213
  end
190
214
 
@@ -201,7 +225,7 @@ module RelatonIso
201
225
  # @return [Hash]
202
226
  def fetch_status(doc)
203
227
  stg, substg = doc.css(
204
- "li.dropdown.active span.stage-code > strong",
228
+ "li.dropdown.active span.stage-code > strong"
205
229
  ).text.split "."
206
230
  RelatonBib::DocumentStatus.new(stage: stg, substage: substg)
207
231
  end
@@ -214,7 +238,7 @@ module RelatonIso
214
238
  # Fetch workgroup.
215
239
  # @param doc [Nokogiri::HTML::Document]
216
240
  # @return [Hash]
217
- def fetch_workgroup(doc)
241
+ def fetch_workgroup(doc) # rubocop:disable Metrics/MethodLength
218
242
  wg_link = doc.css("div.entry-name.entry-block a")[0]
219
243
  # wg_url = DOMAIN + wg_link['href']
220
244
  workgroup = wg_link.text.split "/"
@@ -235,17 +259,19 @@ module RelatonIso
235
259
  # Fetch relations.
236
260
  # @param doc [Nokogiri::HTML::Document]
237
261
  # @return [Array<Hash>]
238
- def fetch_relations(doc)
239
- doc.css("ul.steps li").reduce([]) do |a, r|
262
+ def fetch_relations(doc) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
263
+ doc.css("ul.steps li").reduce([]) do |a, r| # rubocop:disable Metrics/BlockLength
240
264
  r_type = r.css("strong").text
241
265
  date = []
242
266
  type = case r_type
243
267
  when "Previously", "Will be replaced by" then "obsoletes"
244
268
  when "Corrigenda/Amendments", "Revised by", "Now confirmed"
245
- on = doc.xpath('//span[@class="stage-date"][contains(., "-")]').last
269
+ on = doc.xpath(
270
+ '//span[@class="stage-date"][contains(., "-")]'
271
+ ).last
246
272
  if on
247
273
  date << { type: "circulated",
248
- on: on.text }
274
+ on: on.text }
249
275
  "updates"
250
276
  end
251
277
  else r_type
@@ -254,7 +280,7 @@ module RelatonIso
254
280
  else
255
281
  a + r.css("a").map do |id|
256
282
  fref = RelatonBib::FormattedRef.new(
257
- content: id.text, format: "text/plain",
283
+ content: id.text, format: "text/plain"
258
284
  )
259
285
  bibitem = RelatonIsoBib::IsoBibliographicItem.new(
260
286
  formattedref: fref, date: date
@@ -287,12 +313,15 @@ module RelatonIso
287
313
  # Fetch titles.
288
314
  # @param doc [Nokogiri::HTML::Document]
289
315
  # @param lang [String]
290
- # @return [Hash]
316
+ # @return [Array<RelatonBib::TypedTitleString>]
291
317
  def fetch_title(doc, lang)
292
318
  content = doc.at(
293
- "//nav[contains(@class,'eading-condensed')]/h2 | //nav[contains(@class,'eading-condensed')]/h3",
294
- )&.text
295
- RelatonIsoBib::HashConverter.split_title content, lang, script(lang)
319
+ "//nav[contains(@class,'heading-condensed')]/h2 | "\
320
+ "//nav[contains(@class,'heading-condensed')]/h3"
321
+ )&.text&.gsub(/\u2014/, "-")
322
+ return RelatonBib::TypedTitleStringCollection.new unless content
323
+
324
+ RelatonBib::TypedTitleString.from_string content, lang, script(lang)
296
325
  end
297
326
 
298
327
  # Return ISO script code.
@@ -301,7 +330,7 @@ module RelatonIso
301
330
  def script(lang)
302
331
  case lang
303
332
  when "en", "fr" then "Latn"
304
- # when "ru" then "Cyrl"
333
+ # when "ru" then "Cyrl"
305
334
  end
306
335
  end
307
336
 
@@ -310,7 +339,7 @@ module RelatonIso
310
339
  # @param doc [Nokogiri::HTML::Document]
311
340
  # @param ref [String]
312
341
  # @return [Array<Hash>]
313
- def fetch_dates(doc, ref)
342
+ def fetch_dates(doc, ref) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
314
343
  dates = []
315
344
  %r{^[^\s]+\s[\d-]+:(?<ref_date_str>\d{4})} =~ ref
316
345
  pub_date_str = doc.xpath("//span[@itemprop='releaseDate']").text
@@ -378,7 +407,8 @@ module RelatonIso
378
407
  owner_name = ref.match(/.*?(?=\s)/).to_s
379
408
  from = ref.match(/(?<=:)\d{4}/).to_s
380
409
  if from.empty?
381
- from = doc.xpath("//span[@itemprop='releaseDate']").text.match(/\d{4}/).to_s
410
+ from = doc.xpath("//span[@itemprop='releaseDate']").text
411
+ .match(/\d{4}/).to_s
382
412
  end
383
413
  [{ owner: [{ name: owner_name }], from: from }]
384
414
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.1.0"
4
+ VERSION = "1.5.pre"
5
5
  end
@@ -37,6 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "vcr"
38
38
  spec.add_development_dependency "webmock"
39
39
 
40
- spec.add_dependency "relaton-iec", "~> 1.1.0"
41
- spec.add_dependency "relaton-iso-bib", "~> 1.1.0"
40
+ spec.add_dependency "relaton-iec", "~> 1.5.pre"
41
+ spec.add_dependency "relaton-iso-bib", "~> 1.5.pre"
42
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.5.pre
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-03 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.1.0
159
+ version: 1.5.pre
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.1.0
166
+ version: 1.5.pre
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: relaton-iso-bib
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 1.1.0
173
+ version: 1.5.pre
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: 1.1.0
180
+ version: 1.5.pre
181
181
  description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
182
182
  model'
183
183
  email:
@@ -225,7 +225,7 @@ homepage: https://github.com/relaton/relaton-iso
225
225
  licenses:
226
226
  - BSD-2-Clause
227
227
  metadata: {}
228
- post_install_message:
228
+ post_install_message:
229
229
  rdoc_options: []
230
230
  require_paths:
231
231
  - lib
@@ -236,12 +236,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
236
  version: 2.4.0
237
237
  required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  requirements:
239
- - - ">="
239
+ - - ">"
240
240
  - !ruby/object:Gem::Version
241
- version: '0'
241
+ version: 1.3.1
242
242
  requirements: []
243
243
  rubygems_version: 3.0.6
244
- signing_key:
244
+ signing_key:
245
245
  specification_version: 4
246
246
  summary: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
247
247
  model'