relaton-iec 1.11.1 → 1.11.4

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: 26f4ed095f846982958565c16856f12c681fb06f6b4dcdf6d9d51da5e122fda3
4
- data.tar.gz: 9d6d6de7f5ecc68aa0133460e80070e79cf4d58e167ac546dbeb2eb3e18ba537
3
+ metadata.gz: 3693023d890f701035d9decbf0d0866909163bfaebd758e8e7c8e86072815731
4
+ data.tar.gz: 3aedcf623406e1e23311a7eaddd47b9497bd8f9c575e62904f03d4e7b3062224
5
5
  SHA512:
6
- metadata.gz: f9110c1ee9b89a7a31048cb3f57814f16ba0835135849db067e6f4970a63f5f9a3af18507d6a5b040fa4e4a239873264b34e85673abb0b034afc45ca78bbe9fe
7
- data.tar.gz: c2384461bcfd0715d241e0e5cd91f1631158293a57e488acea984f1fbdb3033997fcface2580d04c07212bd1d6e548edfe332da369b21e41a132673848648d5e
6
+ metadata.gz: 9a9917fe56c8a33090ab809a13327cd754c238236e4c027fa0e1939bfb7fa9cb3c27c7708bf930df662bc1737ef36abfd4e00fe79bd56315d69d17073bc5d180
7
+ data.tar.gz: 4076a2815a8428db30e264ce3f2b6224103e4f93babd29913a1b363a1084c8196e8c77c328eb24aca62afd665274b451046e7424c7beda8803d38b921a97e5af
@@ -10,27 +10,4 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
- runs-on: ${{ matrix.os }}
15
- continue-on-error: ${{ matrix.experimental }}
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: [ '3.0', '2.7', '2.6', '2.5' ]
20
- os: [ ubuntu-latest, windows-latest, macos-latest ]
21
- experimental: [ false ]
22
- steps:
23
- - uses: actions/checkout@v2
24
- with:
25
- submodules: true
26
-
27
- # https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
28
- - if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
29
- run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
30
-
31
- - uses: ruby/setup-ruby@v1
32
- with:
33
- ruby-version: ${{ matrix.ruby }}
34
- bundler-cache: true
35
-
36
- - run: bundle exec rake
13
+ uses: relaton/support/.github/workflows/rake.yml@master
data/grammars/biblio.rng CHANGED
@@ -527,7 +527,7 @@
527
527
  </define>
528
528
  <define name="LocalityType">
529
529
  <data type="string">
530
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
530
+ <param name="pattern">section|clause|part|paragraph|chapter|page|title|line|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
531
531
  </data>
532
532
  </define>
533
533
  <define name="referenceFrom">
@@ -851,17 +851,46 @@
851
851
  </define>
852
852
  <define name="bplace">
853
853
  <element name="place">
854
- <optional>
855
- <attribute name="uri">
856
- <data type="anyURI"/>
857
- </attribute>
858
- </optional>
859
- <optional>
860
- <attribute name="region"/>
861
- </optional>
854
+ <choice>
855
+ <text/>
856
+ <group>
857
+ <ref name="bibliocity"/>
858
+ <zeroOrMore>
859
+ <ref name="biblioregion"/>
860
+ </zeroOrMore>
861
+ <zeroOrMore>
862
+ <ref name="bibliocountry"/>
863
+ </zeroOrMore>
864
+ </group>
865
+ </choice>
866
+ </element>
867
+ </define>
868
+ <define name="bibliocity">
869
+ <element name="city">
862
870
  <text/>
863
871
  </element>
864
872
  </define>
873
+ <define name="biblioregion">
874
+ <element name="region">
875
+ <ref name="RegionType"/>
876
+ </element>
877
+ </define>
878
+ <define name="bibliocountry">
879
+ <element name="country">
880
+ <ref name="RegionType"/>
881
+ </element>
882
+ </define>
883
+ <define name="RegionType">
884
+ <optional>
885
+ <attribute name="iso"/>
886
+ </optional>
887
+ <optional>
888
+ <attribute name="recommended">
889
+ <data type="boolean"/>
890
+ </attribute>
891
+ </optional>
892
+ <text/>
893
+ </define>
865
894
  <define name="bprice">
866
895
  <element name="price">
867
896
  <attribute name="currency"/>
@@ -3,6 +3,8 @@
3
3
  module RelatonIec
4
4
  # Hit.
5
5
  class Hit < RelatonBib::Hit
6
+ attr_writer :fetch
7
+
6
8
  # Parse page.
7
9
  # @return [RelatonIec::IecBibliographicItem]
8
10
  def fetch
@@ -32,6 +32,7 @@ module RelatonIec
32
32
  parts.reject { |h| h.hit[:code] == hit.hit[:code] }.each do |hi|
33
33
  isobib = RelatonIec::IecBibliographicItem.new(
34
34
  formattedref: RelatonBib::FormattedRef.new(content: hi.hit[:code]),
35
+ docid: [RelatonBib::DocumentIdentifier.new(id: hi.hit[:code], type: "IEC", primary: true)],
35
36
  )
36
37
  all_parts_item.relation << RelatonBib::DocumentRelation.new(type: "partOf", bibitem: isobib)
37
38
  end
@@ -43,13 +44,35 @@ module RelatonIec
43
44
  # @param ref [String]
44
45
  # @param year [String, nil]
45
46
  # @return [Array<RelatonIec::Hit>]
46
- def hits(ref, year)
47
- from, to = nil
48
- if year
49
- from = Date.strptime year, "%Y"
50
- to = from.next_year.prev_day
47
+ def hits(ref, year) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
48
+ if /61360-4\sDB|ISO[\s\/]IEC\sDIR/.match?(ref)
49
+ fetch_from_gh ref
50
+ else
51
+ from, to = nil
52
+ if year
53
+ from = Date.strptime year, "%Y"
54
+ to = from.next_year.prev_day
55
+ end
56
+ get_results ref, from, to
51
57
  end
52
- get_results ref, from, to
58
+ # file = "../data/#{ref.sub(/^IEC\s/, '').gsub(/[\s\/]/, '_').upcase}.yaml"
59
+ # path = File.expand_path file, __dir__
60
+ # if File.exist? path
61
+ # hash = YAML.safe_load File.read(path, encoding: "utf-8")
62
+ # hit = Hit.new({ code: ref }, self)
63
+ # hit.fetch = IecBibliographicItem.from_hash hash
64
+ # return [hit]
65
+ # end
66
+ end
67
+
68
+ def fetch_from_gh(ref)
69
+ file = ref.sub(/^IEC\s/, "").gsub(/[\s\/]/, "_").upcase
70
+ url = "https://raw.githubusercontent.com/relaton/relaton-data-iec/main/data/#{file}.yaml"
71
+ resp = Net::HTTP.get URI(url)
72
+ hash = YAML.safe_load resp
73
+ hit = Hit.new({ code: ref }, self)
74
+ hit.fetch = IecBibliographicItem.from_hash hash
75
+ [hit]
53
76
  end
54
77
 
55
78
  # @param ref [String]
@@ -3,7 +3,7 @@ module RelatonIec
3
3
  TYPES = %w[
4
4
  international-standard technical-specification technical-report
5
5
  publicly-available-specification international-workshop-agreement
6
- guide industry-technical-agreement
6
+ guide industry-technical-agreement system-reference-delivrabble
7
7
  ].freeze
8
8
 
9
9
  FUNCTION = %w[emc safety enviroment quality-assurance].freeze
@@ -25,9 +25,9 @@ module RelatonIec
25
25
  if args[:updates_document_type] &&
26
26
  !TYPES.include?(args[:updates_document_type])
27
27
  warn "[relaton-iec] WARNING: invalid updates_document_type "\
28
- "\"#{args[:updates_document_type]}\""
28
+ "\"#{args[:updates_document_type]}\""
29
29
  warn "[relaton-iec] allowed updates_document_type values are: "\
30
- "#{TYPES.join(', ')}"
30
+ "#{TYPES.join(', ')}"
31
31
  end
32
32
  @function = args.delete :function
33
33
  @updates_document_type = args.delete :updates_document_type
@@ -43,7 +43,7 @@ module RelatonIec
43
43
  # @return [RelatonIsoBib::IecBibliographicItem]
44
44
  def self.from_hash(hash)
45
45
  item_hash = ::RelatonIec::HashConverter.hash_to_bib(hash)
46
- new **item_hash
46
+ new(**item_hash)
47
47
  end
48
48
 
49
49
  # @param opts [Hash]
@@ -52,7 +52,7 @@ module RelatonIec
52
52
  # @option opts [String] :lang language
53
53
  # @return [String] XML
54
54
  def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
55
- super **opts do |b|
55
+ super(**opts) do |b|
56
56
  if opts[:bibdata]
57
57
  b.ext do
58
58
  b.doctype doctype if doctype
@@ -63,16 +63,16 @@ module RelatonIec
63
63
  structuredidentifier&.to_xml b
64
64
  b.stagename stagename if stagename
65
65
  if updates_document_type
66
- b.send("updates-document-type", updates_document_type)
66
+ b.send(:"updates-document-type", updates_document_type)
67
67
  end
68
68
  unless accessibility_color_inside.nil?
69
- b.send("accessibility-color-inside", accessibility_color_inside)
69
+ b.send(:"accessibility-color-inside", accessibility_color_inside)
70
70
  end
71
- b.send("price-code", price_code) if price_code
72
- b.send("cen-processing", cen_processing) unless cen_processing.nil?
71
+ b.send(:"price-code", price_code) if price_code
72
+ b.send(:"cen-processing", cen_processing) unless cen_processing.nil?
73
73
  b.secretary secretary if secretary
74
74
  if interest_to_committees
75
- b.send("interest-to-committees", interest_to_committees)
75
+ b.send(:"interest-to-committees", interest_to_committees)
76
76
  end
77
77
  end
78
78
  end
@@ -58,19 +58,19 @@ module RelatonIec
58
58
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
59
59
  id = year ? "#{code}:#{year}" : code
60
60
  warn "[relaton-iec] WARNING: no match found online for #{id}. "\
61
- "The code must be exactly like it is on the standards website."
61
+ "The code must be exactly like it is on the standards website."
62
62
  unless missed_years.empty?
63
63
  warn "[relaton-iec] (There was no match for #{year}, though there "\
64
- "were matches found for #{missed_years.join(', ')}.)"
64
+ "were matches found for #{missed_years.join(', ')}.)"
65
65
  end
66
66
  if /\d-\d/.match? code
67
67
  warn "[relaton-iec] The provided document part may not exist, or "\
68
- "the document may no longer be published in parts."
68
+ "the document may no longer be published in parts."
69
69
  else
70
70
  warn "[relaton-iec] If you wanted to cite all document parts for "\
71
- "the reference, use \"#{code} (all parts)\".\nIf the document is "\
72
- "not a standard, use its document type abbreviation (TS, TR, PAS, "\
73
- "Guide)."
71
+ "the reference, use \"#{code} (all parts)\".\nIf the document "\
72
+ "is not a standard, use its document type abbreviation (TS, "\
73
+ "TR, PAS, Guide)."
74
74
  end
75
75
  nil
76
76
  end
@@ -90,33 +90,43 @@ module RelatonIec
90
90
  # @param year [String, nil]
91
91
  # @return [RelatonIec::HitCollection]
92
92
  def search_filter(ref, year) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
93
- %r{
94
- ^(?<code>\S+[^\d]*\s\d+(?:-\w+)*)
95
- (?::(?<year1>\d{4}))?
96
- (?<bundle>\+[^\s/]+)?
97
- (?:/(?<corr>AMD\s\d+))?
98
- }x =~ ref.upcase
99
- year ||= year1
100
- corr&.sub! " ", ""
93
+ rp1 = ref_parts ref.upcase
94
+ year ||= rp1[:year]
95
+ corr = rp1[:corr]&.sub " ", ""
101
96
  warn "[relaton-iec] (\"#{ref}\") fetching..."
102
- result = search(code, year)
103
- if result.empty? && /(?<=-)(?<part>[\w-]+)/ =~ code
97
+ result = search(rp1[:code], year)
98
+ code = result.text.dup
99
+ if result.empty? && /(?<=\d-)(?<part>[\w-]+)/ =~ rp1[:code]
104
100
  # try to search packaged standard
105
- result = search code, year, part
101
+ result = search rp1[:code], year, part
102
+ pkg_std = result.any?
103
+ end
104
+ result = search rp1[:code] if result.empty?
105
+ if pkg_std
106
+ code.sub!(/(?<=\d-)#{part}/, part[0])
107
+ else
108
+ code.sub!(/-[-\d]+/, "")
106
109
  end
107
- result = search code if result.empty?
108
- code = result.text.dup
109
- code&.sub!(/((?:-\w+)+)/, "")
110
110
  result.select do |i|
111
- %r{
112
- ^(?<code2>\S+[^\d]*\s\d+)(?:-\w+)*(?::\d{4})?
113
- (?<bundle2>\+[^\s/]+)?
114
- (?:/(?<corr2>AMD\d+))?
115
- }x =~ i.hit[:code]
116
- code == code2 && bundle == bundle2 && corr == corr2
111
+ rp2 = ref_parts i.hit[:code]
112
+ code2 = if pkg_std
113
+ rp2[:code].sub(/(?<=\d-\d)\d+/, "")
114
+ else
115
+ rp2[:code].sub(/-[-\d]+/, "")
116
+ end
117
+ code == code2 && rp1[:bundle] == rp2[:bundle] && corr == rp2[:corr]
117
118
  end
118
119
  end
119
120
 
121
+ def ref_parts(ref)
122
+ %r{
123
+ ^(?<code>[^\d]+(?:\d+(?:-\w+)*)?(?:\s?[A-Z]+)?(?:\sSUP)?)
124
+ (?::(?<year>\d{4}))?
125
+ (?<bundle>\+[^\s/]+)?
126
+ (?:/(?<corr>AMD\s?\d+))?
127
+ }x.match ref
128
+ end
129
+
120
130
  def iev(code = "IEC 60050")
121
131
  RelatonIsoBib::XMLParser.from_xml(<<~"XML")
122
132
  <bibitem>
@@ -191,8 +201,8 @@ module RelatonIec
191
201
  # @return [Array<String, nil>]
192
202
  def code_year(ref, part)
193
203
  %r{
194
- ^(?<code>\S+[^\d]*\s\d+((?:-\w+)+)?)
195
- (:(?<year>\d{4}))?
204
+ ^(?<code>\S+[^\d]*\s\d+(?:-\w+)*)
205
+ (?::(?<year>\d{4}))?
196
206
  }x =~ ref
197
207
  code.sub!(/-\d+/, "") if part
198
208
  [code, year]
@@ -17,17 +17,18 @@ module RelatonIec
17
17
 
18
18
  TYPES = {
19
19
  "ISO" => "international-standard",
20
- "TS" => "technicalSpecification",
21
- "TR" => "technicalReport",
22
- "PAS" => "publiclyAvailableSpecification",
23
- "AWI" => "appruvedWorkItem",
24
- "CD" => "committeeDraft",
25
- "FDIS" => "finalDraftInternationalStandard",
26
- "NP" => "newProposal",
27
- "DIS" => "draftInternationalStandard",
28
- "WD" => "workingDraft",
20
+ "TS" => "technical-specification",
21
+ "TR" => "technical-report",
22
+ "PAS" => "publicly-available-specification",
23
+ "AWI" => "appruved-work-item",
24
+ "CD" => "committee-draft",
25
+ "FDIS" => "final-draft-international-standard",
26
+ "NP" => "new-proposal",
27
+ "DIS" => "draft-international-standard",
28
+ "WD" => "working-draft",
29
29
  "R" => "recommendation",
30
30
  "Guide" => "guide",
31
+ "SRD" => "system-reference-delivrabble",
31
32
  }.freeze
32
33
 
33
34
  class << self
@@ -194,10 +195,12 @@ module RelatonIec
194
195
  when "withdrawn" then "obsoletes"
195
196
  else r_type
196
197
  end
197
- fref = RelatonBib::FormattedRef.new(
198
- content: r.at("FULL_NAME").text, format: "text/plain",
198
+ ref = r.at("FULL_NAME").text
199
+ fref = RelatonBib::FormattedRef.new content: ref, format: "text/plain"
200
+ bibitem = IecBibliographicItem.new(
201
+ formattedref: fref,
202
+ docid: [RelatonBib::DocumentIdentifier.new(id: ref, type: "IEC", primary: true)],
199
203
  )
200
- bibitem = IecBibliographicItem.new(formattedref: fref)
201
204
  { type: type, bibitem: bibitem }
202
205
  end
203
206
  end
@@ -218,9 +221,10 @@ module RelatonIec
218
221
  # @param doc [Nokogiri::HTML::Document]
219
222
  # @return [String]
220
223
  def fetch_type(doc)
221
- doc.at(
224
+ type = doc.at(
222
225
  '//th[contains(., "Publication type")]/following-sibling::td/span',
223
- ).text.downcase.tr " ", "-"
226
+ ).text
227
+ TYPES[type] || type.downcase.tr(" ", "-")
224
228
  end
225
229
 
226
230
  # Fetch titles.
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.11.1".freeze
2
+ VERSION = "1.11.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-23 00:00:00.000000000 Z
11
+ date: 2022-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml