relaton-iec 1.7.6 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +36 -0
  3. data/.rubocop.yml +1 -1
  4. data/README.adoc +25 -0
  5. data/grammars/basicdoc.rng +165 -20
  6. data/grammars/biblio.rng +5 -6
  7. data/grammars/iec.rng +96 -1
  8. data/grammars/isodoc.rng +532 -16
  9. data/grammars/isostandard.rng +56 -103
  10. data/grammars/reqt.rng +31 -2
  11. data/lib/relaton_iec/basic_block/alignment.rb +30 -0
  12. data/lib/relaton_iec/basic_block/basic_block.rb +15 -0
  13. data/lib/relaton_iec/basic_block/citation_type.rb +32 -0
  14. data/lib/relaton_iec/basic_block/dl.rb +60 -0
  15. data/lib/relaton_iec/basic_block/eref.rb +10 -0
  16. data/lib/relaton_iec/basic_block/eref_type.rb +39 -0
  17. data/lib/relaton_iec/basic_block/formula.rb +34 -0
  18. data/lib/relaton_iec/basic_block/image.rb +41 -0
  19. data/lib/relaton_iec/basic_block/index.rb +27 -0
  20. data/lib/relaton_iec/basic_block/index_xref.rb +31 -0
  21. data/lib/relaton_iec/basic_block/note.rb +21 -0
  22. data/lib/relaton_iec/basic_block/paragraph.rb +27 -0
  23. data/lib/relaton_iec/basic_block/paragraph_with_footnote.rb +29 -0
  24. data/lib/relaton_iec/basic_block/reference_format.rb +38 -0
  25. data/lib/relaton_iec/basic_block/stem.rb +30 -0
  26. data/lib/relaton_iec/basic_block/table.rb +115 -0
  27. data/lib/relaton_iec/basic_block/text_element.rb +27 -0
  28. data/lib/relaton_iec/hash_converter.rb +1 -1
  29. data/lib/relaton_iec/hit_collection.rb +1 -1
  30. data/lib/relaton_iec/iec_bibliographic_item.rb +93 -1
  31. data/lib/relaton_iec/iec_bibliography.rb +6 -5
  32. data/lib/relaton_iec/processor.rb +1 -2
  33. data/lib/relaton_iec/scrapper.rb +10 -13
  34. data/lib/relaton_iec/tc_sc_officers_note.rb +24 -0
  35. data/lib/relaton_iec/version.rb +1 -1
  36. data/lib/relaton_iec/xml_parser.rb +21 -1
  37. data/relaton_iec.gemspec +2 -4
  38. metadata +25 -37
  39. data/.github/workflows/macos.yml +0 -34
  40. data/.github/workflows/ubuntu.yml +0 -33
  41. data/.github/workflows/windows.yml +0 -35
@@ -0,0 +1,27 @@
1
+ module BasicBlock
2
+ class TextElement
3
+ TAGS = %w[em strong sub sup tt underline strike smallcap br hr keyword rp
4
+ rt ruby pagebreak bookmark].freeze
5
+
6
+ #
7
+ # @param [String] tag
8
+ # @param [Array<String, BasicBlock::TextElement, BasicBlock::Stem>,
9
+ # String] content
10
+ #
11
+ def initialize(tag:, content:)
12
+ unless TAGS.include? tag
13
+ warn "[basic-block] WARNING: invalid tag \"#{tag}\""
14
+ warn "[basic-block] allowed tags are: #{TAGS.join ', '}"
15
+ end
16
+ @tag = tag
17
+ @content = content
18
+ end
19
+
20
+ # @param [Nokogiri::XML::Builder]
21
+ def to_xml(builder)
22
+ builder.send @tag do |b|
23
+ @content.each { |c| c.is_a?(String) ? c : c.to_xml(b) }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,7 +7,7 @@ module RelatonIec
7
7
  # @param item [Hash]
8
8
  # @retirn [RelatonIec::IecBibliographicItem]
9
9
  def bib_item(item)
10
- IecBibliographicItem.new(item)
10
+ IecBibliographicItem.new(**item)
11
11
  end
12
12
  end
13
13
  end
@@ -25,7 +25,7 @@ module RelatonIec
25
25
  def to_all_parts # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
26
26
  parts = @array.reject { |h| h.part.nil? }
27
27
  hit = parts.min_by &:part
28
- return @array.first.fetch lang unless hit
28
+ return @array.first&.fetch unless hit
29
29
 
30
30
  bibitem = hit.fetch
31
31
  all_parts_item = bibitem.to_all_parts
@@ -3,7 +3,99 @@ module RelatonIec
3
3
  TYPES = %w[
4
4
  international-standard technical-specification technical-report
5
5
  publicly-available-specification international-workshop-agreement
6
- guide
6
+ guide industry-technical-agreement
7
7
  ].freeze
8
+
9
+ FUNCTION = %w[emc safety enviroment quality-assurance].freeze
10
+
11
+ # @return [String, nil]
12
+ attr_reader :function, :updates_document_type, :price_code, :secretary,
13
+ :interest_to_committees
14
+
15
+ # @return [Boolean, nil]
16
+ attr_reader :accessibility_color_inside, :cen_processing
17
+
18
+ # attr_reader :tc_sc_officers_note
19
+
20
+ def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
21
+ if args[:function] && !FUNCTION.include?(args[:function])
22
+ warn "[relaton-iec] WARNING: invalid function \"#{args[:function]}\""
23
+ warn "[relaton-iec] allowed function values are: #{FUNCTION.join(', ')}"
24
+ end
25
+ if args[:updates_document_type] &&
26
+ !TYPES.include?(args[:updates_document_type])
27
+ warn "[relaton-iec] WARNING: invalid updates_document_type "\
28
+ "\"#{args[:updates_document_type]}\""
29
+ warn "[relaton-iec] allowed updates_document_type values are: "\
30
+ "#{TYPES.join(', ')}"
31
+ end
32
+ @function = args.delete :function
33
+ @updates_document_type = args.delete :updates_document_type
34
+ @accessibility_color_inside = args.delete :accessibility_color_inside
35
+ @price_code = args.delete :price_code
36
+ @cen_processing = args.delete :cen_processing
37
+ @secretary = args.delete :secretary
38
+ @interest_to_committees = args.delete :interest_to_committees
39
+ super
40
+ end
41
+
42
+ # @param hash [Hash]
43
+ # @return [RelatonIsoBib::IecBibliographicItem]
44
+ def self.from_hash(hash)
45
+ item_hash = ::RelatonIec::HashConverter.hash_to_bib(hash)
46
+ new **item_hash
47
+ end
48
+
49
+ # @param opts [Hash]
50
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
51
+ # @option opts [Boolean] :bibdata
52
+ # @option opts [String] :lang language
53
+ # @return [String] XML
54
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
55
+ super **opts do |b|
56
+ if opts[:bibdata]
57
+ b.ext do
58
+ b.doctype doctype if doctype
59
+ b.horizontal horizontal unless horizontal.nil?
60
+ b.function function if function
61
+ editorialgroup&.to_xml b
62
+ ics.each { |i| i.to_xml b }
63
+ structuredidentifier&.to_xml b
64
+ b.stagename stagename if stagename
65
+ if updates_document_type
66
+ b.send("updates-document-type", updates_document_type)
67
+ end
68
+ unless accessibility_color_inside.nil?
69
+ b.send("accessibility-color-inside", accessibility_color_inside)
70
+ end
71
+ b.send("price-code", price_code) if price_code
72
+ b.send("cen-processing", cen_processing) unless cen_processing.nil?
73
+ b.secretary secretary if secretary
74
+ if interest_to_committees
75
+ b.send("interest-to-committees", interest_to_committees)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ # @return [Hash]
83
+ def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
84
+ hash = super
85
+ hash["function"] = function if function
86
+ if updates_document_type
87
+ hash["updates_document_type"] = updates_document_type
88
+ end
89
+ unless accessibility_color_inside.nil?
90
+ hash["accessibility_color_inside"] = accessibility_color_inside
91
+ end
92
+ hash["price_code"] = price_code if price_code
93
+ hash["cen_processing"] = cen_processing unless cen_processing.nil?
94
+ hash["secretary"] = secretary if secretary
95
+ if interest_to_committees
96
+ hash["interest_to_committees"] = interest_to_committees
97
+ end
98
+ hash
99
+ end
8
100
  end
9
101
  end
@@ -21,7 +21,7 @@ module RelatonIec
21
21
  # @param part [String, nil] search for packaged stndard if not nil
22
22
  # @return [RelatonIec::HitCollection]
23
23
  def search(text, year = nil, part = nil)
24
- HitCollection.new text, year&.strip, part
24
+ HitCollection.new text.sub(/(^\w+)\//, '\1 '), year&.strip, part
25
25
  rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
26
26
  raise RelatonBib::RequestError, "Could not access http://www.iec.ch"
27
27
  end
@@ -105,6 +105,7 @@ module RelatonIec
105
105
  result = search code, year, part
106
106
  end
107
107
  result = search code if result.empty?
108
+ code = result.text.dup
108
109
  code&.sub! /((?:-\w+)+)/, ""
109
110
  result.select do |i|
110
111
  %r{
@@ -158,8 +159,8 @@ module RelatonIec
158
159
  # Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
159
160
  # If no match, returns any years which caused mismatch, for error
160
161
  # reporting
161
- def results_filter(result, ref, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
162
- r_code, r_year = code_year ref, result.part
162
+ def results_filter(result, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
163
+ r_code, r_year = code_year result.text, result.part
163
164
  r_year ||= year
164
165
  missed_years = []
165
166
  missed_parts = false
@@ -186,7 +187,7 @@ module RelatonIec
186
187
  { ret: ret, years: missed_years, missed_parts: missed_parts }
187
188
  end
188
189
 
189
- # @param ref [string]
190
+ # @param ref [String]
190
191
  # @param part [String, nil]
191
192
  # @return [Array<String, nil>]
192
193
  def code_year(ref, part)
@@ -204,7 +205,7 @@ module RelatonIec
204
205
  # @return [RelatonIec::IecBibliographicItem, nil]
205
206
  def iecbib_get(code, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
206
207
  result = search_filter(code, year) || return
207
- ret = results_filter(result, code, year, opts)
208
+ ret = results_filter(result, year, opts)
208
209
  if ret[:ret]
209
210
  if ret[:missed_parts]
210
211
  warn "[relaton-iec] WARNING: #{code} found as #{ret[:ret].docidentifier.first.id} "\
@@ -26,8 +26,7 @@ module RelatonIec
26
26
  # @param hash [Hash]
27
27
  # @return [RelatonIsoBib::IecBibliographicItem]
28
28
  def hash_to_bib(hash)
29
- item_hash = ::RelatonIec::HashConverter.hash_to_bib(hash)
30
- ::RelatonIec::IecBibliographicItem.new item_hash
29
+ ::RelatonIec::IecBibliographicItem.from_hash hash
31
30
  end
32
31
 
33
32
  # Returns hash of XML grammar
@@ -241,14 +241,7 @@ module RelatonIec
241
241
 
242
242
  def fetch_contributors(code)
243
243
  code.sub(/\s.*/, "").split("/").map do |abbrev|
244
- case abbrev
245
- when "ISO"
246
- name = "International Organization for Standardization"
247
- url = "www.iso.org"
248
- when "IEC"
249
- name = "International Electrotechnical Commission"
250
- url = "www.iec.ch"
251
- end
244
+ name, url = name_url abbrev
252
245
  { entity: { name: name, url: url, abbreviation: abbrev },
253
246
  role: [type: "publisher"] }
254
247
  end
@@ -285,11 +278,7 @@ module RelatonIec
285
278
  # @return [Array<Hash>]
286
279
  def fetch_copyright(code, doc)
287
280
  abbreviation = code.match(/.*?(?=\s)/).to_s
288
- case abbreviation
289
- when "IEC"
290
- name = "International Electrotechnical Commission"
291
- url = "www.iec.ch"
292
- end
281
+ name, url = name_url abbreviation
293
282
  from = code.match(/(?<=:)\d{4}/).to_s
294
283
  if from.empty?
295
284
  from = doc.xpath("//span[@itemprop='releaseDate']").text
@@ -301,6 +290,14 @@ module RelatonIec
301
290
  }]
302
291
  end
303
292
  # rubocop:enable Metrics/MethodLength
293
+
294
+ def name_url(abbrev)
295
+ case abbrev
296
+ when "ISO" then ["International Organization for Standardization", "www.iso.org"]
297
+ when "IEC" then ["International Electrotechnical Commission", "www.iec.ch"]
298
+ when "CISPR" then ["International special committee on radio interference", "www.iec.ch"]
299
+ end
300
+ end
304
301
  end
305
302
  end
306
303
  end
@@ -0,0 +1,24 @@
1
+ module RelatonIec
2
+ class TcScOfficersNote
3
+ # @return [Array<RelatonIec::BasicBlock>]
4
+ attr_reader :basic_blocks
5
+
6
+ #
7
+ # @param [Array<BasicBlock::ParagraphWithFootnote>] basic_blocks
8
+ #
9
+ def initialize(basic_blocks)
10
+ @basic_blocks = basic_blocks
11
+ end
12
+
13
+ #
14
+ # XML serialization
15
+ #
16
+ # @param [Nokogiri::XML::Builder] builder
17
+ #
18
+ def to_xml(builder)
19
+ builder.send "tc-sc-officers-note" do |b|
20
+ basic_blocks.each { |bb| bb.to_xml b }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.7.6".freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
@@ -1,13 +1,33 @@
1
1
  module RelatonIec
2
2
  class XMLParser < RelatonIsoBib::XMLParser
3
3
  class << self
4
+ # Override RelatonIsoBib::XMLParser.item_data method.
5
+ # @param isoitem [Nokogiri::XML::Element]
6
+ # @returtn [Hash]
7
+ def item_data(isoitem) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
8
+ data = super
9
+ ext = isoitem.at "./ext"
10
+ return data unless ext
11
+
12
+ data[:function] = ext.at("./function")&.text
13
+ data[:updates_document_type] = ext.at("./updates-document-type")&.text
14
+ aci = ext.at("./accessibility-color-inside")
15
+ data[:accessibility_color_inside] = aci.text == "true" if aci
16
+ data[:price_code] = ext.at("./price-code")&.text
17
+ cp = ext.at("./cen-processing")
18
+ data[:cen_processing] = cp.text == "true" if cp
19
+ data[:secretary] = ext.at("./secretary")&.text
20
+ data[:interest_to_committees] = ext.at("./interest-to-committees")&.text
21
+ data
22
+ end
23
+
4
24
  private
5
25
 
6
26
  # override RelatonIsoBib::IsoBibliographicItem.bib_item method
7
27
  # @param item_hash [Hash]
8
28
  # @return [RelatonIec::IecBibliographicItem]
9
29
  def bib_item(item_hash)
10
- IecBibliographicItem.new item_hash
30
+ IecBibliographicItem.new **item_hash
11
31
  end
12
32
  end
13
33
  end
data/relaton_iec.gemspec CHANGED
@@ -21,19 +21,17 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
25
25
 
26
- spec.add_development_dependency "debase"
27
26
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
28
27
  spec.add_development_dependency "pry-byebug"
29
28
  spec.add_development_dependency "rake", "~> 10.0"
30
29
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "ruby-debug-ide"
32
30
  spec.add_development_dependency "ruby-jing"
33
31
  spec.add_development_dependency "simplecov"
34
32
  spec.add_development_dependency "vcr"
35
33
  spec.add_development_dependency "webmock"
36
34
 
37
35
  spec.add_dependency "addressable"
38
- spec.add_dependency "relaton-iso-bib", "~> 1.7.0"
36
+ spec.add_dependency "relaton-iso-bib", "~> 1.9.0"
39
37
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.6
4
+ version: 1.9.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: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: equivalent-xml
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: ruby-debug-ide
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
69
  - !ruby/object:Gem::Dependency
98
70
  name: ruby-jing
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +142,14 @@ dependencies:
170
142
  requirements:
171
143
  - - "~>"
172
144
  - !ruby/object:Gem::Version
173
- version: 1.7.0
145
+ version: 1.9.0
174
146
  type: :runtime
175
147
  prerelease: false
176
148
  version_requirements: !ruby/object:Gem::Requirement
177
149
  requirements:
178
150
  - - "~>"
179
151
  - !ruby/object:Gem::Version
180
- version: 1.7.0
152
+ version: 1.9.0
181
153
  description: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem
182
154
  model'
183
155
  email:
@@ -186,9 +158,7 @@ executables: []
186
158
  extensions: []
187
159
  extra_rdoc_files: []
188
160
  files:
189
- - ".github/workflows/macos.yml"
190
- - ".github/workflows/ubuntu.yml"
191
- - ".github/workflows/windows.yml"
161
+ - ".github/workflows/rake.yml"
192
162
  - ".gitignore"
193
163
  - ".rspec"
194
164
  - ".rubocop.yml"
@@ -206,6 +176,23 @@ files:
206
176
  - grammars/isostandard.rng
207
177
  - grammars/reqt.rng
208
178
  - lib/relaton_iec.rb
179
+ - lib/relaton_iec/basic_block/alignment.rb
180
+ - lib/relaton_iec/basic_block/basic_block.rb
181
+ - lib/relaton_iec/basic_block/citation_type.rb
182
+ - lib/relaton_iec/basic_block/dl.rb
183
+ - lib/relaton_iec/basic_block/eref.rb
184
+ - lib/relaton_iec/basic_block/eref_type.rb
185
+ - lib/relaton_iec/basic_block/formula.rb
186
+ - lib/relaton_iec/basic_block/image.rb
187
+ - lib/relaton_iec/basic_block/index.rb
188
+ - lib/relaton_iec/basic_block/index_xref.rb
189
+ - lib/relaton_iec/basic_block/note.rb
190
+ - lib/relaton_iec/basic_block/paragraph.rb
191
+ - lib/relaton_iec/basic_block/paragraph_with_footnote.rb
192
+ - lib/relaton_iec/basic_block/reference_format.rb
193
+ - lib/relaton_iec/basic_block/stem.rb
194
+ - lib/relaton_iec/basic_block/table.rb
195
+ - lib/relaton_iec/basic_block/text_element.rb
209
196
  - lib/relaton_iec/hash_converter.rb
210
197
  - lib/relaton_iec/hit.rb
211
198
  - lib/relaton_iec/hit_collection.rb
@@ -214,6 +201,7 @@ files:
214
201
  - lib/relaton_iec/processor.rb
215
202
  - lib/relaton_iec/scrapper.rb
216
203
  - lib/relaton_iec/statuses.yml
204
+ - lib/relaton_iec/tc_sc_officers_note.rb
217
205
  - lib/relaton_iec/version.rb
218
206
  - lib/relaton_iec/xml_parser.rb
219
207
  - relaton_iec.gemspec
@@ -229,14 +217,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
217
  requirements:
230
218
  - - ">="
231
219
  - !ruby/object:Gem::Version
232
- version: 2.4.0
220
+ version: 2.5.0
233
221
  required_rubygems_version: !ruby/object:Gem::Requirement
234
222
  requirements:
235
223
  - - ">="
236
224
  - !ruby/object:Gem::Version
237
225
  version: '0'
238
226
  requirements: []
239
- rubygems_version: 3.0.6
227
+ rubygems_version: 3.2.3
240
228
  signing_key:
241
229
  specification_version: 4
242
230
  summary: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem