relaton-ieee 1.12.3 → 1.12.6

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: ae6ce7435bdf251b1180ba075e3585f7075c289ab5ad58bbf7e26706d3fe10fe
4
- data.tar.gz: b6475b2c93336560e490fea100879389d4323a7854180114d724443af0332e52
3
+ metadata.gz: 5d518d9c4d21f989941f871c62682bdb996e8d060997e1211fb6bca708cfbd32
4
+ data.tar.gz: 6b160e9ed08862a141fd4068ce70be0a2cf5ea97196013d87c8cf9af0a4ea133
5
5
  SHA512:
6
- metadata.gz: 7a630fdfff66077109cbbbad786783488c79a687de9d60b75b1ed42b03a46ab98c11542abbdbb7497dbe3220183d1512f7457339edfad3b459591fe2a3c06676
7
- data.tar.gz: f2027e366b04f6cc59c0e219526082d9f171d22fdbbf91c42077b07e0c37a8508a715f8fb9eb7ae55c50eaf8974970fff15b7f6ade8389438061aaceace766fc
6
+ metadata.gz: d8768c3e725410a80ccf1075e33491e1ff99b6c5051576e1441734d9ef31018ffc9077e3ec01ab0bcfb353efd43018a304aff0967beb2b9839a8271a0fdaaa9b
7
+ data.tar.gz: b79ca69d3aa30965fef5ce03b910739fa9e4f1816cbfe37b2d66ddb069b4134160f1c73ad2e603a69d214998e5a737819c7cf5949327491275767df25eab6835
@@ -0,0 +1,56 @@
1
+ module RelatonIeee
2
+ class BallotingGroup
3
+ TYPES = %w[individual entity].freeze
4
+
5
+ # @return [String]
6
+ attr_reader :type, :content
7
+
8
+ #
9
+ # Initialize balloting group
10
+ #
11
+ # @param [String] type type
12
+ # @param [String] content content
13
+ #
14
+ def initialize(type:, content:)
15
+ unless TYPES.include?(type)
16
+ warn "[relaton-ieee] WARNING: type of Balloting group must be one of #{TYPES.join(', ')}"
17
+ end
18
+
19
+ @type = type
20
+ @content = content
21
+ end
22
+
23
+ #
24
+ # Render balloting group to XML
25
+ #
26
+ # @param [Nokogiri::XML::Builder] builder XML builder
27
+ #
28
+ def to_xml(builder)
29
+ builder.send :"balloting-group", content, type: type
30
+ end
31
+
32
+ #
33
+ # Render balloting group to Hash
34
+ #
35
+ # @return [Hash] balloting group as Hash
36
+ #
37
+ def to_hash
38
+ { "type" => type, "content" => content }
39
+ end
40
+
41
+ #
42
+ # Render balloting group to AsciiBib
43
+ #
44
+ # @param [String] prefix Prefix
45
+ #
46
+ # @return [String] AsciiBib
47
+ #
48
+ def to_asciibib(prefix = "")
49
+ pref = prefix.empty? ? prefix : "#{prefix}."
50
+ pref += "balloting-group"
51
+ out = "#{pref}.type:: #{type}\n"
52
+ out += "#{pref}.content:: #{content}\n"
53
+ out
54
+ end
55
+ end
56
+ end
@@ -35,6 +35,7 @@ module RelatonIeee
35
35
  #
36
36
  def parse # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
37
37
  args = {
38
+ fetched: Date.today.to_s,
38
39
  type: "standard",
39
40
  docnumber: docnumber,
40
41
  title: parse_title,
@@ -50,6 +51,7 @@ module RelatonIeee
50
51
  link: parse_link,
51
52
  keyword: parse_keyword,
52
53
  ics: parse_ics,
54
+ editorialgroup: parse_editorialgroup,
53
55
  }
54
56
  IeeeBibliographicItem.new(**args)
55
57
  end
@@ -113,8 +115,11 @@ module RelatonIeee
113
115
  #
114
116
  # @return [Array<RelatonBib::DocumentIdentifier>]
115
117
  #
116
- def parse_docid
117
- ids = [{ id: pubid.to_s, type: "IEEE", primary: true }]
118
+ def parse_docid # rubocop:disable Metrics/MethodLength
119
+ ids = [
120
+ { id: pubid.to_s, type: "IEEE", primary: true },
121
+ { id: pubid.to_s(trademark: true), scope: "trademark", type: "IEEE", primary: true },
122
+ ]
118
123
  isbn = doc.at("./publicationinfo/isbn")
119
124
  ids << { id: isbn.text, type: "ISBN" } if isbn
120
125
  doi = doc.at("./volume/article/articleinfo/articledoi")
@@ -124,6 +129,11 @@ module RelatonIeee
124
129
  end
125
130
  end
126
131
 
132
+ #
133
+ # Create PubID
134
+ #
135
+ # @return [RelatonIeee::RawbibIdParser] PubID
136
+ #
127
137
  def pubid
128
138
  @pubid ||= begin
129
139
  nt = doc.at("./normtitle").text
@@ -220,7 +230,7 @@ module RelatonIeee
220
230
  #
221
231
  def parse_status
222
232
  stage = doc.at("./publicationinfo/standard_status").text
223
- RelatonBib::DocumentStatus.new stage: stage
233
+ DocumentStatus.new stage: stage
224
234
  end
225
235
 
226
236
  #
@@ -274,5 +284,17 @@ module RelatonIeee
274
284
  RelatonBib::ICS.new code: ics[:codenum], text: ics.text
275
285
  end
276
286
  end
287
+
288
+ #
289
+ # Parse editorialgroup
290
+ #
291
+ # @return [RelatonIeee::EditorialGroup, nil] editorialgroup or nil
292
+ #
293
+ def parse_editorialgroup
294
+ committee = doc.xpath(
295
+ "./publicationinfo/pubsponsoringcommitteeset/pubsponsoringcommittee",
296
+ ).map &:text
297
+ EditorialGroup.new committee: committee if committee.any?
298
+ end
277
299
  end
278
300
  end
@@ -0,0 +1,14 @@
1
+ module RelatonIeee
2
+ class DocumentStatus < RelatonBib::DocumentStatus
3
+ class Stage < RelatonBib::DocumentStatus::Stage
4
+ STAGES = %w[developing active inactive].freeze
5
+
6
+ def initialize(value:, abbreviation: nil)
7
+ unless STAGES.include?(value.downcase)
8
+ warn "[relaton-ieee] Stage value must be one of #{STAGES.join(', ')}"
9
+ end
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,83 @@
1
+ module RelatonIeee
2
+ class EditorialGroup
3
+ # @return [String]
4
+ attr_reader :society, :working_group
5
+ # @return [RelatonIeee::BallotingGroup] Balloting group
6
+ attr_reader :balloting_group
7
+ # @return [Array<String>] Committee
8
+ attr_reader :committee
9
+
10
+ #
11
+ # Initialize editorial group
12
+ #
13
+ # @param [Hash] **args Hash of arguments
14
+ # @option args [String] :society Society
15
+ # @option args [RelatonIeee::BallotingGroup, Hash] :balloting_group Balloting group
16
+ # @option args [String] :working_group Working group
17
+ # @option args [Array<String>] :committee Committee
18
+ #
19
+ def initialize(**args)
20
+ unless args[:committee].is_a?(Array) && args[:committee].any?
21
+ raise ArgumentError, ":committee is required"
22
+ end
23
+
24
+ @society = args[:society]
25
+ @balloting_group = if args[:balloting_group].is_a?(Hash)
26
+ BallotingGroup.new(**args[:balloting_group])
27
+ else args[:balloting_group]
28
+ end
29
+ @working_group = args[:working_group]
30
+ @committee = args[:committee]
31
+ end
32
+
33
+ def presence?
34
+ true
35
+ end
36
+
37
+ #
38
+ # Render editorial group to XML
39
+ #
40
+ # @param [Nokogiri::XML::Builder] builder XML builder
41
+ #
42
+ def to_xml(builder)
43
+ builder.editorialgroup do |b|
44
+ b.society society if society
45
+ balloting_group&.to_xml(b)
46
+ b.send :"working-group", working_group if working_group
47
+ committee.each { |c| b.committee c }
48
+ end
49
+ end
50
+
51
+ #
52
+ # Render editorial group to Hash
53
+ #
54
+ # @return [Hash] editorial group as Hash
55
+ #
56
+ def to_hash
57
+ hash = {}
58
+ hash["society"] = society if society
59
+ hash["balloting_group"] = balloting_group.to_hash if balloting_group
60
+ hash["working_group"] = working_group if working_group
61
+ hash["committee"] = committee if committee
62
+ hash
63
+ end
64
+
65
+ #
66
+ # Render editorial group to AsciiBib
67
+ #
68
+ # @param [String] prefix Prefix
69
+ #
70
+ # @return [String] AsciiBib
71
+ #
72
+ def to_asciibib(prefix = "")
73
+ pref = prefix.empty? ? prefix : "#{prefix}."
74
+ pref += "editorialgroup"
75
+ out = ""
76
+ out += "#{pref}.society:: #{society}\n" if society
77
+ out += balloting_group.to_asciibib(pref) if balloting_group
78
+ out += "#{pref}.working-group:: #{working_group}\n" if working_group
79
+ committee.each { |c| out += "#{pref}.committee:: #{c}\n" }
80
+ out
81
+ end
82
+ end
83
+ end
@@ -4,13 +4,13 @@ module RelatonIeee
4
4
  # @param args [Hash]
5
5
  # @param neated [TrueClas, FalseClass] default true
6
6
  # @return [Hash]
7
- def hash_to_bib(args)
8
- hash = super
9
- return nil unless hash.is_a?(Hash)
7
+ # def hash_to_bib(args)
8
+ # hash = super
9
+ # return nil unless hash.is_a?(Hash)
10
10
 
11
- committee_hash_to_bib hash
12
- hash
13
- end
11
+ # editorialgroup_hash_to_bib hash
12
+ # hash
13
+ # end
14
14
 
15
15
  # @param item_hash [Hash]
16
16
  # @return [RelatonIeee::IeeeBibliographicItem]
@@ -19,10 +19,10 @@ module RelatonIeee
19
19
  end
20
20
 
21
21
  # @param hash [Hash]
22
- def committee_hash_to_bib(hash)
23
- return unless hash[:committee]
22
+ def editorialgroup_hash_to_bib(hash)
23
+ return unless hash[:editorialgroup]
24
24
 
25
- hash[:committee] = hash[:committee].map { |c| Committee.new(**c) }
25
+ hash[:editorialgroup] = EditorialGroup.new(**hash[:editorialgroup])
26
26
  end
27
27
  end
28
28
  end
@@ -4,37 +4,39 @@ require "fileutils"
4
4
 
5
5
  module RelatonIeee
6
6
  class HitCollection < RelatonBib::HitCollection
7
- DOMAIN = "https://standards.ieee.org".freeze
8
- # DATADIR = File.expand_path ".relaton/ogc/", Dir.home
9
- # DATAFILE = File.expand_path "bibliography.json", DATADIR
10
- # ETAGFILE = File.expand_path "etag.txt", DATADIR
7
+ # DOMAIN = "https://standards.ieee.org".freeze
8
+ GH_URL = "https://raw.githubusercontent.com/relaton/relaton-data-ieee/main/data/".freeze
11
9
 
12
10
  # @param reference [Strig]
13
11
  # @param opts [Hash]
14
12
  def initialize(reference) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
15
13
  super
16
- code1 = reference.sub(/^IEEE\s(Std\s)?/, "")
17
- url = "#{DOMAIN}/wp-admin/admin-ajax.php"
18
- query = reference.gsub("/", " ")
19
- resp = Faraday.post url, { action: "ieee_cloudsearch", q: query }
20
- json = JSON.parse resp.body
21
- unless json["results"]
22
- @array = []
23
- return
24
- end
14
+ ref = reference.gsub(/[\s,:\/]/, "_").squeeze("_").upcase
15
+ url = "#{GH_URL}#{ref}.yaml"
16
+ resp = Faraday.get url
17
+ hit = YAML.load resp.body
18
+ # code1 = reference.sub(/^IEEE\s(Std\s)?/, "")
19
+ # url = "#{DOMAIN}/wp-admin/admin-ajax.php"
20
+ # query = reference.gsub("/", " ")
21
+ # resp = Faraday.post url, { action: "ieee_cloudsearch", q: query }
22
+ # json = JSON.parse resp.body
23
+ # unless json["results"]
24
+ # @array = []
25
+ # return
26
+ # end
25
27
 
26
- @array = json["results"]["hits"]["hit"].reduce([]) do |s, hit|
27
- flds = hit["fields"]
28
- /^(?:\w+\s)?(?<code2>[A-Z\d.]+)(?:-(?<year>\d{4}))?/ =~ flds["meta_designation_l"]
29
- next s unless code2 && code1 =~ %r{^#{code2}}
28
+ # @array = json["results"]["hits"]["hit"].reduce([]) do |s, hit|
29
+ # flds = hit["fields"]
30
+ # /^(?:\w+\s)?(?<code2>[A-Z\d.]+)(?:-(?<year>\d{4}))?/ =~ flds["meta_designation_l"]
31
+ # next s unless code2 && code1 =~ %r{^#{code2}}
30
32
 
31
- hit_data = {
32
- ref: flds["meta_designation_l"],
33
- year: year.to_i,
34
- url: flds["doc_id_l"],
35
- }
36
- s << Hit.new(hit_data, self)
37
- end.sort_by { |h| h.hit[:year].to_s + h.hit[:url] }.reverse
33
+ # hit_data = {
34
+ # ref: flds["meta_designation_l"],
35
+ # year: year.to_i,
36
+ # url: flds["doc_id_l"],
37
+ # }
38
+ # s << Hit.new(hit_data, self)
39
+ # end.sort_by { |h| h.hit[:year].to_s + h.hit[:url] }.reverse
38
40
  end
39
41
  end
40
42
  end
@@ -1,12 +1,30 @@
1
1
  module RelatonIeee
2
2
  class IeeeBibliographicItem < RelatonBib::BibliographicItem
3
- # @return [Array<RelatonIeee::Committee>]
4
- attr_reader :committee
3
+ TYPES = %w[guide recommended-practice standard].freeze
4
+ SUBTYPES = %w[amendment corrigendum erratum].freeze
5
5
 
6
- # @param committee [Array<RelatonIeee::Committee>]
6
+ # @return [RelatonIeee::EditorialGroup, nil]
7
+ attr_reader :editorialgroup
8
+
9
+ # @return [Boolean, nil] Trial use
10
+ attr_reader :trialuse
11
+
12
+ #
13
+ # @param [Hash] args
14
+ # @option args [Boolean, nil] :trialuse Trial use
15
+ # @option args [Array<RelatonIeee::EditorialGroup>] :editorialgroup Editorial group
16
+ #
7
17
  def initialize(**args)
8
- @committee = args.delete(:committee) || []
18
+ if args[:doctype] && !TYPES.include?(args[:doctype])
19
+ warn "[relaton-ieee] doctype should be one of #{TYPES.join(', ')}"
20
+ end
21
+ if args[:docsubtype] && !SUBTYPES.include?(args[:docsubtype])
22
+ warn "[relaton-ieee] docsubtype should be one of #{SUBTYPES.join(', ')}"
23
+ end
24
+ eg = args.delete(:editorialgroup)
25
+ @trialuse = args.delete(:trialuse)
9
26
  super
27
+ @editorialgroup = eg
10
28
  end
11
29
 
12
30
  # @param hash [Hash]
@@ -21,11 +39,15 @@ module RelatonIeee
21
39
  # @option opts [Boolean] :bibdata
22
40
  # @option opts [String] :lang language
23
41
  # @return [String] XML
24
- def to_xml(**opts)
42
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
25
43
  super(**opts) do |bldr|
26
- if opts[:bibdata] && committee.any?
44
+ if opts[:bibdata] && (doctype || subdoctype || !trialuse.nil? || editorialgroup || ics.any?)
27
45
  bldr.ext do |b|
28
- committee.each { |c| c.to_xml b }
46
+ b.doctype doctype if doctype
47
+ b.subdoctype subdoctype if subdoctype
48
+ b.send :"trial-use", trialuse unless trialuse.nil?
49
+ editorialgroup&.to_xml(b)
50
+ ics.each { |ic| ic.to_xml(b) }
29
51
  end
30
52
  end
31
53
  end
@@ -34,7 +56,7 @@ module RelatonIeee
34
56
  # @return [Hash]
35
57
  def to_hash
36
58
  hash = super
37
- hash["committee"] = committee.map &:to_hash if committee.any?
59
+ hash["trialuse"] = trialuse unless trialuse.nil?
38
60
  hash
39
61
  end
40
62
 
@@ -42,7 +64,7 @@ module RelatonIeee
42
64
  # @return [String]
43
65
  def to_asciibib(prefix = "")
44
66
  out = super
45
- committee.each { |c| out += c.to_asciibib prefix, committee.size }
67
+ out += "#{prefix}.trialuse:: #{trialuse}\n" unless trialuse.nil?
46
68
  out
47
69
  end
48
70
  end
@@ -1,12 +1,20 @@
1
1
  module RelatonIeee
2
2
  class IeeeBibliography
3
3
  class << self
4
- # @param text [String]
4
+ GH_URL = "https://raw.githubusercontent.com/relaton/relaton-data-ieee/main/data/".freeze
5
+
6
+ # @param code [String]
5
7
  # @return [RelatonIeee::HitCollection]
6
- def search(text)
7
- HitCollection.new text
8
+ def search(code)
9
+ # HitCollection.new text
10
+ ref = code.sub(/Std\s/i, "").gsub(/[\s,:\/]/, "_").squeeze("_").upcase
11
+ url = "#{GH_URL}#{ref}.yaml"
12
+ resp = Faraday.get url
13
+ return unless resp.status == 200
14
+
15
+ IeeeBibliographicItem.from_hash YAML.safe_load resp.body
8
16
  rescue Faraday::ConnectionFailed
9
- raise RelatonBib::RequestError, "Could not access #{HitCollection::DOMAIN}"
17
+ raise RelatonBib::RequestError, "Could not access #{GH_URL}"
10
18
  end
11
19
 
12
20
  # @param code [String] the IEEE standard Code to look up (e..g "528-2019")
@@ -15,17 +23,17 @@ module RelatonIeee
15
23
  #
16
24
  # @return [Hash, NilClass] returns { ret: RelatonBib::BibliographicItem }
17
25
  # if document is found else returns NilClass
18
- def get(code, year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
+ def get(code, _year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
19
27
  warn "[relaton-ieee] (\"#{code}\") fetching..."
20
- result = search(code) || (return nil)
21
- year ||= code.match(/(?<=-)\d{4}/)&.to_s
22
- ret = bib_results_filter(result, code, year)
23
- if ret[:ret]
24
- item = ret[:ret].fetch
28
+ item = search(code)
29
+ # year ||= code.match(/(?<=-)\d{4}/)&.to_s
30
+ # ret = bib_results_filter(result, code, year)
31
+ if item # ret[:ret]
32
+ # item = ret[:ret].fetch
25
33
  warn "[relaton-ieee] (\"#{code}\") found #{item.docidentifier.first.id}"
26
34
  item
27
- else
28
- fetch_ref_err(code, year, ret[:years])
35
+ # else
36
+ # fetch_ref_err(code, year, ret[:years])
29
37
  end
30
38
  end
31
39
 
@@ -42,44 +50,44 @@ module RelatonIeee
42
50
  # @param opts [Hash] options
43
51
  #
44
52
  # @return [Hash]
45
- def bib_results_filter(result, ref, year) # rubocop:disable Metrics/AbcSize
46
- rp1 = ref_parts ref
47
- missed_years = []
48
- result.each do |hit|
49
- rp2 = ref_parts hit.hit[:ref]
50
- next if rp1[:code] != rp2[:code] || rp1[:corr] != rp2[:corr]
53
+ # def bib_results_filter(result, ref, year) # rubocop:disable Metrics/AbcSize
54
+ # rp1 = ref_parts ref
55
+ # missed_years = []
56
+ # result.each do |hit|
57
+ # rp2 = ref_parts hit.hit[:ref]
58
+ # next if rp1[:code] != rp2[:code] || rp1[:corr] != rp2[:corr]
51
59
 
52
- return { ret: hit } if !year
60
+ # return { ret: hit } if !year
53
61
 
54
- return { ret: hit } if year.to_i == hit.hit[:year]
62
+ # return { ret: hit } if year.to_i == hit.hit[:year]
55
63
 
56
- missed_years << hit.hit[:year]
57
- end
58
- { years: missed_years.uniq }
59
- end
64
+ # missed_years << hit.hit[:year]
65
+ # end
66
+ # { years: missed_years.uniq }
67
+ # end
60
68
 
61
- def ref_parts(ref)
62
- %r{
63
- ^(?:IEEE\s(?:Std\s)?)?
64
- (?<code>[^-/]+)
65
- (?:-(?<year>\d{4}))?
66
- (?:/(?<corr>\w+\s\d+-\d{4}))?
67
- }x.match ref
68
- end
69
+ # def ref_parts(ref)
70
+ # %r{
71
+ # ^(?:IEEE\s(?:Std\s)?)?
72
+ # (?<code>[^-/]+)
73
+ # (?:-(?<year>\d{4}))?
74
+ # (?:/(?<corr>\w+\s\d+-\d{4}))?
75
+ # }x.match ref
76
+ # end
69
77
 
70
78
  # @param code [Strig]
71
79
  # @param year [String]
72
80
  # @param missed_years [Array<Strig>]
73
- def fetch_ref_err(code, year, missed_years)
74
- id = year ? "#{code} year #{year}" : code
75
- warn "[relaton-ieee] WARNING: no match found online for #{id}. "\
76
- "The code must be exactly like it is on the standards website."
77
- unless missed_years.empty?
78
- warn "[relaton-ieee] (There was no match for #{year}, though there were matches "\
79
- "found for #{missed_years.join(', ')}.)"
80
- end
81
- nil
82
- end
81
+ # def fetch_ref_err(code, year, missed_years)
82
+ # id = year ? "#{code} year #{year}" : code
83
+ # warn "[relaton-ieee] WARNING: no match found online for #{id}. "\
84
+ # "The code must be exactly like it is on the standards website."
85
+ # unless missed_years.empty?
86
+ # warn "[relaton-ieee] (There was no match for #{year}, though there were matches "\
87
+ # "found for #{missed_years.join(', ')}.)"
88
+ # end
89
+ # nil
90
+ # end
83
91
  end
84
92
  end
85
93
  end
@@ -48,15 +48,20 @@ module RelatonIeee
48
48
  #
49
49
  # PubId string representation
50
50
  #
51
+ # @param [Boolean] trademark if true, add trademark symbol
52
+ #
51
53
  # @return [String]
52
54
  #
53
- def to_s # rubocop:disable Metrics/AbcSize
55
+ def to_s(trademark: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
54
56
  out = number
55
57
  out = "#{stage} #{out}" if stage
56
58
  out = "#{approval} #{out}" if approval
57
59
  out = "#{status} #{out}" if status
58
60
  out = "#{publisher} #{out}" if publisher
59
61
  out += ".#{part}" if part
62
+ if trademark
63
+ out += out.match?(/^IEEE\s(Std\s)?(802|2030)/) ? "\u00AE" : "\u2122"
64
+ end
60
65
  out += edition_to_s + draft_to_s + rev_to_s + corr_to_s + amd_to_s
61
66
  out + year_to_s + month_to_s + redline_to_s
62
67
  end
@@ -120,10 +125,12 @@ module RelatonIeee
120
125
  #
121
126
  # PubId string representation
122
127
  #
128
+ # @param [Boolean] trademark if true, add trademark symbol
129
+ #
123
130
  # @return [String]
124
131
  #
125
- def to_s
126
- pubid.map(&:to_s).join("/")
132
+ def to_s(trademark: false)
133
+ pubid.map { |id| id.to_s(trademark: trademark) }.join("/")
127
134
  end
128
135
 
129
136
  #
@@ -309,7 +309,8 @@ module RelatonIeee
309
309
  PubId.new(publisher: $1, number: $2, stage: $3, year: $5, month: mn($4))
310
310
 
311
311
  # publisher, stage, number, part, draft
312
- when /^([A-Z\/]+)[.-]([[:alnum:].-]+)[\/_]D([[:alnum:].]+)[\/_](#{STAGES})/o
312
+ when /^([A-Z\/]+)[.-]([[:alnum:].-]+)[\/_]D([[:alnum:].]+)[\/_](#{STAGES})/o,
313
+ /^(\w+)[.-]([[:alnum:].]+)[\/\s_]D([\d.]+)_(#{STAGES})/o
313
314
  PubId.new(publisher: "IEEE", number: $1, part: sp($2), draft: dn($3), stage: $4)
314
315
 
315
316
  # publisher, stage, number, year
@@ -471,9 +472,10 @@ module RelatonIeee
471
472
  def yn(year)
472
473
  return year if year.size == 4
473
474
 
475
+ y = Date.today.year.to_s[2..4].to_i + 1
474
476
  case year.to_i
475
- when 0..25 then "20#{year}"
476
- when 26..99 then "19#{year}"
477
+ when 0...y then "20#{year}"
478
+ when y..99 then "19#{year}"
477
479
  end
478
480
  end
479
481
 
@@ -496,7 +498,7 @@ module RelatonIeee
496
498
  #
497
499
  # @param [Strin] edition
498
500
  #
499
- # @return [String]
501
+ # @return [String, Integer]
500
502
  #
501
503
  def en(edition)
502
504
  case edition
@@ -18,7 +18,7 @@ module RelatonIeee
18
18
  language: ["en"],
19
19
  script: ["Latn"],
20
20
  date: fetch_date(doc),
21
- committee: fetch_committee(doc),
21
+ editorialgroup: fetch_editorialgroup(doc),
22
22
  place: ["Piscataway, NJ, USA"],
23
23
  )
24
24
  end
@@ -40,8 +40,11 @@ module RelatonIeee
40
40
  # @return [Array<RelatonBib::DocumentIdentifier>]
41
41
  def fetch_docid(ref)
42
42
  args = { id: ref, type: "IEEE", primary: true }
43
- args[:scope] = "trademark" if ref.match?(/^IEEE\s(?:Std\s)?(?:802|2030)/)
44
- [RelatonBib::DocumentIdentifier.new(**args)]
43
+ ids = [RelatonBib::DocumentIdentifier.new(**args)]
44
+ args[:scope] = "trademark"
45
+ tm = ref.match?(/^IEEE\s(Std\s)?(802|2030)/) ? "\u00AE" : "\u2122"
46
+ args[:id] = ref.sub(/^(IEEE\s(?:Std\s)?[.\w]+)/) { |s| "#{s}#{tm}" }
47
+ ids << RelatonBib::DocumentIdentifier.new(**args)
45
48
  end
46
49
 
47
50
  # @param url [String]
@@ -56,7 +59,7 @@ module RelatonIeee
56
59
  stage = doc.at("//dd[@id='stnd-status']")
57
60
  return unless stage
58
61
 
59
- RelatonBib::DocumentStatus.new(stage: stage.text.split.first)
62
+ DocumentStatus.new(stage: stage.text.split.first)
60
63
  end
61
64
 
62
65
  # @param identifier [String]
@@ -114,8 +117,6 @@ module RelatonIeee
114
117
  # )
115
118
  # end
116
119
 
117
- # rubocop:disable Metrics/MethodLength
118
-
119
120
  # @param date [Nokogiri::HTML::Document]
120
121
  # @return [Array<RelatonBib::BibliographicDate>]
121
122
  def fetch_date(doc)
@@ -131,33 +132,23 @@ module RelatonIeee
131
132
  dates
132
133
  end
133
134
 
134
- # rubocop:disable Metrics/AbcSize
135
-
135
+ #
136
136
  # @param doc [Nokogiri::HTML::Document]
137
- # @return [Array<RelatonIeee::Committee>]
138
- def fetch_committee(doc)
139
- committees = []
140
- sponsor = doc.at "//dd[@id='stnd-committee']/text()"
141
- if sponsor
142
- committees << Committee.new(type: "sponsor", name: sponsor.text.strip)
143
- end
144
- sponsor = doc.at "//td[.='Standards Committee']/following-sibling::td/div/a"
145
- if sponsor
146
- committees << Committee.new(type: "standard", name: sponsor.text)
147
- end
148
- working = doc.at "//dd[@id='stnd-working-group']/text()"
149
- if working
150
- chair = doc.at "//dd[@id='stnd-working-group-chair']"
151
- committees << Committee.new(type: "working", name: working.text.strip,
152
- chair: chair.text)
153
- end
154
- society = doc.at "//dd[@id='stnd-society']/text()"
155
- if society
156
- committees << Committee.new(type: "society", name: society.text.strip)
157
- end
158
- committees
137
+ #
138
+ # @return [RelatonIeee::EditorialGroup]
139
+ #
140
+ def fetch_editorialgroup(doc) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
141
+ committees = doc.xpath(
142
+ "//dd[@id='stnd-committee']/text()",
143
+ "//td[.='Standards Committee']/following-sibling::td/div/a",
144
+ ).map { |c| c.text.strip }
145
+ wg = doc.at("//dd[@id='stnd-working-group']/text()")&.text&.strip
146
+ # chair = doc.at "//dd[@id='stnd-working-group-chair']"
147
+ society = doc.at("//dd[@id='stnd-society']/text()")&.text&.strip
148
+ return unless committees.any? || wg || society
149
+
150
+ EditorialGroup.new(society: society, working_group: wg, committee: committees)
159
151
  end
160
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
161
152
  end
162
153
  end
163
154
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonIeee
2
- VERSION = "1.12.3".freeze
2
+ VERSION = "1.12.6".freeze
3
3
  end
@@ -11,18 +11,47 @@ module RelatonIeee
11
11
  ext = item.at "./ext"
12
12
  return data unless ext
13
13
 
14
- data[:committee] = ext.xpath("./committee").map do |c|
15
- Committee.new(
16
- type: c[:type], name: c.at("name").text, chair: c.at("chair")&.text
17
- )
18
- end
14
+ data[:editorialgroup] = parse_editorialgroup(item)
19
15
  data
20
16
  end
21
17
 
22
18
  # @param item_hash [Hash]
23
19
  # @return [RelatonIeee::IeeeBibliographicItem]
24
20
  def bib_item(item_hash)
25
- IeeeBibliographicItem.new **item_hash
21
+ IeeeBibliographicItem.new(**item_hash)
22
+ end
23
+
24
+ #
25
+ # Parse editorialgroup
26
+ #
27
+ # @param [Nokogiri::XML::Element] item XML element
28
+ #
29
+ # @return [RelatonIeee::EditorialGroup] Editorial group
30
+ #
31
+ def parse_editorialgroup(item)
32
+ eg = item.at "./ext/editorialgroup"
33
+ return unless eg
34
+
35
+ society = eg.at("./society")&.text
36
+ bg = parse_balloting_group(eg)
37
+ wg = eg.at("./working-group")&.text
38
+ committee = eg.xpath("./committee").map(&:text)
39
+ EditorialGroup.new(society: society, balloting_group: bg,
40
+ working_group: wg, committee: committee)
41
+ end
42
+
43
+ #
44
+ # Parse balloting group
45
+ #
46
+ # @param [Nokogiri::XML::Element] editorialgroup XML element
47
+ #
48
+ # @return [RelatonIeee::BallotingGroup] Balloting group
49
+ #
50
+ def parse_balloting_group(editorialgroup)
51
+ bg = editorialgroup.at("./balloting-group")
52
+ return unless bg
53
+
54
+ BallotingGroup.new type: bg[:type], content: bg.text
26
55
  end
27
56
  end
28
57
  end
data/lib/relaton_ieee.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require "digest/md5"
2
+ require "faraday"
2
3
  require "yaml"
3
4
  require "relaton_bib"
4
5
  require "relaton_ieee/version"
6
+ require "relaton_ieee/document_status"
5
7
  require "relaton_ieee/ieee_bibliography"
6
- require "relaton_ieee/hit_collection"
7
- require "relaton_ieee/hit"
8
- require "relaton_ieee/scrapper"
8
+ # require "relaton_ieee/scrapper"
9
9
  require "relaton_ieee/ieee_bibliographic_item"
10
- require "relaton_ieee/committee"
10
+ require "relaton_ieee/editorial_group"
11
+ require "relaton_ieee/balloting_group"
11
12
  require "relaton_ieee/xml_parser"
12
13
  require "relaton_ieee/bibxml_parser"
13
14
  require "relaton_ieee/hash_converter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ieee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.3
4
+ version: 1.12.6
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-07-06 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -146,10 +146,12 @@ files:
146
146
  - grammars/isodoc.rng
147
147
  - grammars/reqt.rng
148
148
  - lib/relaton_ieee.rb
149
+ - lib/relaton_ieee/balloting_group.rb
149
150
  - lib/relaton_ieee/bibxml_parser.rb
150
- - lib/relaton_ieee/committee.rb
151
151
  - lib/relaton_ieee/data_fetcher.rb
152
152
  - lib/relaton_ieee/data_parser.rb
153
+ - lib/relaton_ieee/document_status.rb
154
+ - lib/relaton_ieee/editorial_group.rb
153
155
  - lib/relaton_ieee/hash_converter.rb
154
156
  - lib/relaton_ieee/hit.rb
155
157
  - lib/relaton_ieee/hit_collection.rb
@@ -1,46 +0,0 @@
1
- module RelatonIeee
2
- class Committee
3
- # @return [String]
4
- attr_reader :type, :name
5
-
6
- # @return [String, NilClass]
7
- attr_reader :chair
8
-
9
- # @param type [String]
10
- # @param name [String]
11
- # @param chair [String, NilClass]
12
- def initialize(type:, name:, chair: nil)
13
- @type = type
14
- @name = name
15
- @chair = chair
16
- end
17
-
18
- # @param builder [Nokogiri::XML::Builder]
19
- def to_xml(builder)
20
- builder.committee type: type do |b|
21
- b.name name
22
- b.chair chair if chair
23
- end
24
- end
25
-
26
- # @return [Hash]
27
- def to_hash
28
- hash = { "type" => type, "name" => name }
29
- hash["chair"] = chair if chair
30
- hash
31
- end
32
-
33
- # @param prefix [String]
34
- # @param count [Integer]
35
- # @return [String]
36
- def to_asciibib(prefix, count)
37
- pref = prefix.empty? ? prefix : prefix + "."
38
- pref += "committee"
39
- out = count > 1 ? "#{pref}::\n" : ""
40
- out += "#{pref}.type:: #{type}\n"
41
- out += "#{pref}.name:: #{name}\n"
42
- out += "#{pref}.chair:: #{chair}\n" if chair
43
- out
44
- end
45
- end
46
- end