relaton-bipm 1.14.6 → 1.14.7

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: f72520efca5d2a8525b052758d95563c5ca6d57d22b85b146e4ff77e02ee2594
4
- data.tar.gz: 57803ee16e558e356c0529599ffa8ba881ef85dba99d8b28a1f936a577f711f7
3
+ metadata.gz: fca66f613215d88c2a6211038fa877a18c3239a6dc967058935d656f93a38bbf
4
+ data.tar.gz: 973ef9e8f3ae01e4a993c5b1fa5499cecd41c070b1ece0ec45b947d07e6bc009
5
5
  SHA512:
6
- metadata.gz: e44f8da41d1c91944196344e85921988c14e5771f976af31471b14bfa216084717942b43b5e3ddc0053891c23e5bb4b7c9d4d9f07ad1abd9b825028fb2b49cd1
7
- data.tar.gz: 1b6de32f1454222514c9867d86a1bf970d0b42fce78b8f927459e8907a9715ebaf45c17366acfbe2112599fd3c07fc5a93d9729fd43e7565e67dee6acbeb52c3
6
+ metadata.gz: '0387b51f65c91b25c0957ee23d4781de82914bf8e6e32fd03ec7aa6cfb0506648983cf724cfed09a061e3e01967863d24a2948c074b76e83a6cab852ee452028'
7
+ data.tar.gz: 9cec1161eb66bb984ae573b0b880da67b4085b574acae5c6f44c80669a2f57f10ab422bbd7a54e419f65c159925ccf1815f08ac1ace269e2ac0808cce1e10791
@@ -36,8 +36,6 @@ module RelatonBipm
36
36
  basename = File.join @data_fetcher.output, File.basename(f).sub(/(?:-(?:en|fr))?\.rxl$/, "")
37
37
  outfile = "#{basename}.#{@data_fetcher.ext}"
38
38
  key = hash1["docnumber"] || basename
39
- @data_fetcher.index[[key]] = outfile
40
- @data_fetcher.index_new.add_or_update [key], outfile
41
39
  @data_fetcher.index2.add_or_update Id.new(key).to_hash, outfile
42
40
  hash = if File.exist? outfile
43
41
  warn_duplicate = false
@@ -1,6 +1,6 @@
1
1
  module RelatonBipm
2
2
  class DataFetcher
3
- attr_reader :output, :format, :ext, :files, :index, :index_new, :index2
3
+ attr_reader :output, :format, :ext, :files, :index2
4
4
 
5
5
  #
6
6
  # Initialize fetcher
@@ -13,9 +13,6 @@ module RelatonBipm
13
13
  @format = format
14
14
  @ext = format.sub(/^bib/, "")
15
15
  @files = []
16
- @index_path = "index.yaml"
17
- @index = File.exist?(@index_path) ? YAML.load_file(@index_path) : {}
18
- @index_new = Relaton::Index.find_or_create :BIPM, file: "index-bipm.yaml"
19
16
  @index2 = Relaton::Index.find_or_create :BIPM, file: "index2.yaml"
20
17
  end
21
18
 
@@ -47,8 +44,6 @@ module RelatonBipm
47
44
  when "bipm-si-brochure" then BipmSiBrochureParser.parse(self)
48
45
  when "rawdata-bipm-metrologia" then RawdataBipmMetrologia::Fetcher.fetch(self)
49
46
  end
50
- File.write @index_path, index.to_yaml, encoding: "UTF-8"
51
- index_new.save
52
47
  index2.save
53
48
  end
54
49
 
@@ -61,7 +61,7 @@ module RelatonBipm
61
61
  # @param [String] body name of body
62
62
  #
63
63
  def fetch_type(dir, body) # rubocop:disable Metrics/AbcSize
64
- type = dir.split("/").last.split("-").first.sub(/s$/, "")
64
+ type = dir.split("/").last.split("-").first.sub(/s$/, "").capitalize
65
65
  body_dir = File.join @data_fetcher.output, body.downcase
66
66
  FileUtils.mkdir_p body_dir
67
67
  outdir = File.join body_dir, type.downcase
@@ -74,7 +74,7 @@ module RelatonBipm
74
74
  #
75
75
  # @param [String] en_file Path to English file
76
76
  # @param [String] body Body name
77
- # @param [String] type Type of Recommendation/Decision/Resolution
77
+ # @param [String] type meeting
78
78
  # @param [String] dir output directory
79
79
  #
80
80
  def fetch_meeting(en_file, body, type, dir) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -84,7 +84,7 @@ module RelatonBipm
84
84
 
85
85
  file = "#{num}.#{@data_fetcher.ext}"
86
86
  path = File.join dir, file
87
- hash = bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"]
87
+ hash = meeting_bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"]
88
88
  if @data_fetcher.files.include?(path) && part
89
89
  add_part hash, part
90
90
  item = RelatonBipm::BipmBibliographicItem.new(**hash)
@@ -95,7 +95,7 @@ module RelatonBipm
95
95
  path = File.join dir, "#{num}-#{part}.#{@data_fetcher.ext}"
96
96
  elsif part
97
97
  hash[:title].each { |t| t[:content] = t[:content].sub(/\s\(.+\)$/, "") }
98
- h = bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"]
98
+ h = meeting_bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"]
99
99
  add_part h, part
100
100
  part_item = RelatonBipm::BipmBibliographicItem.new(**h)
101
101
  part_item_path = File.join dir, "#{num}-#{part}.#{@data_fetcher.ext}"
@@ -171,9 +171,9 @@ module RelatonBipm
171
171
  num = "0" if num == year
172
172
  num_justed = num.rjust 2, "0"
173
173
  type = r["type"].capitalize
174
- docnum = create_docnum args[:body], type, num, date
174
+ docnum = create_resolution_docnum args[:body], type, num, date
175
175
  hash[:id] = create_id(args[:body], type, num_justed, date)
176
- hash[:docid] = create_docids docnum
176
+ hash[:docid] = create_resolution_docids args[:body], type, num, date
177
177
  hash[:docnumber] = docnum
178
178
  hash[:language] = %w[en fr]
179
179
  hash[:script] = ["Latn"]
@@ -230,11 +230,8 @@ module RelatonBipm
230
230
  # @param [String] path path to YAML file
231
231
  #
232
232
  def add_to_index(item, path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
233
- key = item.docidentifier.select { |i| i.type == "BIPM" }.map &:id
234
- @data_fetcher.index[key] = path
235
- @data_fetcher.index_new.add_or_update key, path
236
- key2 = Id.new(item.docnumber).to_hash
237
- @data_fetcher.index2.add_or_update key2, path
233
+ key = Id.new(item.docnumber).to_hash
234
+ @data_fetcher.index2.add_or_update key, path
238
235
  end
239
236
 
240
237
  #
@@ -373,20 +370,20 @@ module RelatonBipm
373
370
  end
374
371
 
375
372
  #
376
- # Create hash from BIPM meeting/resolution
373
+ # Create hash from BIPM meeting
377
374
  #
378
375
  # @param [Hash] **args Hash of arguments
379
- # @option args [String] :type Type of meeting/resolution
376
+ # @option args [String] :type meeting
380
377
  # @option args [Hash] :en Hash of English metadata
381
378
  # @option args [Hash] :fr Hash of French metadata
382
- # @option args [String] :id ID of meeting/resolution
383
- # @option args [String] :num Number of meeting/resolution
379
+ # @option args [String] :id ID of meeting
380
+ # @option args [String] :num Number of meeting
384
381
  # @option args [Array<Hash>] :src Array of links to bipm-data-outcomes
385
382
  # @option args [String] :pdf link to PDF
386
383
  #
387
384
  # @return [Hash] Hash of BIPM meeting/resolution
388
385
  #
389
- def bibitem(**args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
386
+ def meeting_bibitem(**args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
390
387
  docnum = create_meeting_docnum args[:body], args[:type], args[:num], args[:en]["date"]
391
388
  hash = { title: [], type: "proceedings", doctype: args[:type],
392
389
  place: [RelatonBib::Place.new(city: "Paris")] }
@@ -428,49 +425,51 @@ module RelatonBipm
428
425
  end
429
426
 
430
427
  #
431
- # Creata a document number
428
+ # Creata resolution document number
432
429
  #
433
- # @param [<Type>] body <description>
434
- # @param [<Type>] type <description>
435
- # @param [<Type>] num <description>
436
- # @param [<Type>] date <description>
430
+ # @param [String] body CIPM, CGPM, CCTF
431
+ # @param [String] type Recommendation, Resolution, Decision
432
+ # @param [String] num number of recommendation, resolution, decision
433
+ # @param [String] date date of publication
437
434
  #
438
- # @return [<Type>] <description>
435
+ # @return [String] document number
439
436
  #
440
- def create_docnum(body, type, num, date)
437
+ def create_resolution_docnum(body, type, num, date)
441
438
  year = Date.parse(date).year
442
- # if special_id_case? body, type, year
443
- # id = "#{type.capitalize} #{body}"
444
- # id += "/#{num}" if num.to_i.positive?
445
- # else
446
439
  id = "#{body} #{SHORTTYPE[type.capitalize]}"
447
440
  id += " #{num}" if num.to_i.positive?
448
- # end
449
441
  "#{id} (#{year})"
450
442
  end
451
443
 
444
+ #
445
+ # Create meeting document number
446
+ #
447
+ # @param [String] body CIPM, CGPM, CCTF
448
+ # @param [String] type meeting
449
+ # @param [String] num number of meeting
450
+ # @param [String] date date of publication
451
+ #
452
+ # @return [String] <description>
453
+ #
452
454
  def create_meeting_docnum(body, type, num, date)
453
455
  year = Date.parse(date).year
454
- "#{body} #{num}th #{type} (#{year})"
456
+ ord = %w[th st nd rd th th th th th th][num.to_i % 10]
457
+ "#{body} #{num}#{ord} #{type} (#{year})"
455
458
  end
456
459
 
457
460
  #
458
461
  # Create ID
459
462
  #
460
- # @param [String] body body of meeting
461
- # @param [String] type type of meeting
462
- # @param [String, nil] num part number
463
+ # @param [String] body CIPM, CGPM, CCTF
464
+ # @param [String] type meeting, recommendation, resolution, decision
465
+ # @param [String, nil] num number of meeting, recommendation, resolution, decision
463
466
  # @param [String] date published date
464
467
  #
465
468
  # @return [String] ID
466
469
  #
467
470
  def create_id(body, type, num, date)
468
471
  year = Date.parse(date).year
469
- # if special_id_case?(body, type, year)
470
- # [type.capitalize, body, year]
471
- # else
472
472
  [body, SHORTTYPE[type.capitalize], year, num].compact.join("-")
473
- # end
474
473
  end
475
474
 
476
475
  #
@@ -482,10 +481,10 @@ module RelatonBipm
482
481
  #
483
482
  # @return [Boolean] is special case
484
483
  #
485
- # def special_id_case?(body, type, year)
486
- # (body == "CIPM" && type == "Decision" && year.to_i > 2011) ||
487
- # (body == "JCRB" && %w[recomendation resolution descision].include?(type))
488
- # end
484
+ def special_id_case?(body, type, year)
485
+ (body == "CIPM" && type == "Decision" && year.to_i > 2011) ||
486
+ (body == "JCRB" && %w[Recomendation Resolution Descision].include?(type))
487
+ end
489
488
 
490
489
  #
491
490
  # Create documetn IDs
@@ -494,38 +493,62 @@ module RelatonBipm
494
493
  #
495
494
  # @return [Array<RelatonBib::DocumentIdentifier>] document IDs
496
495
  #
497
- def create_docids(id)
498
- en_id = id.sub(/(\s\(\d{4})(\))$/, '\1, E\2')
499
- fr_id = id.sub(/(\s\(\d{4})(\))$/, '\1, F\2')
500
- [
501
- make_docid(id: id, type: "BIPM", primary: true),
502
- make_docid(id: en_id, type: "BIPM", primary: true, language: "en", script: "Latn"),
503
- make_docid(id: fr_id, type: "BIPM", primary: true, language: "fr", script: "Latn"),
504
- # create_docid_fr(en_id),
505
- ]
496
+ def create_resolution_docids(body, type, num, date)
497
+ year = Date.parse(date).year
498
+ ids = []
499
+ resolution_short_ids(body, type, num, year) { |id| ids << id }
500
+ resolution_long_ids(body, type, num, year) { |id| ids << id }
501
+ end
502
+
503
+ def resolution_short_ids(body, type, num, year, &_block)
504
+ short_type = SHORTTYPE[type]
505
+ id = "#{body} #{short_type}"
506
+ id += " #{num}" if num.to_i.positive?
507
+
508
+ short = "#{id} (#{year})"
509
+ yield make_docid(id: short, type: "BIPM", primary: true)
510
+
511
+ en = "#{id} (#{year}, E)"
512
+ yield make_docid(id: en, type: "BIPM", primary: true, language: "en", script: "Latn")
513
+
514
+ fr = "#{id} (#{year}, F)"
515
+ yield make_docid(id: fr, type: "BIPM", primary: true, language: "fr", script: "Latn")
516
+ end
517
+
518
+ def resolution_long_ids(body, type, num, year, &_block)
519
+ en = "#{body} #{type}"
520
+ en += " #{num}" if num.to_i.positive?
521
+ en += " (#{year})"
522
+ yield make_docid id: en, type: "BIPM-long", language: "en", script: "Latn"
523
+
524
+ fr = resolution_fr_long_id(body, type, num, year)
525
+ yield make_docid id: fr, type: "BIPM-long", language: "fr", script: "Latn"
526
+
527
+ yield make_docid(id: "#{en} / #{fr}", type: "BIPM-long")
528
+ end
529
+
530
+ def resolution_fr_long_id(body, type, num, year)
531
+ fr = TRANSLATIONS[type] || type
532
+ if special_id_case? body, type, year
533
+ fr += " #{body}"
534
+ fr += "/#{num}" if num.to_i.positive?
535
+ else
536
+ fr += " #{num}" if num.to_i.positive?
537
+ fr += body == "CGPM" ? " de la" : " du"
538
+ fr += " #{body}"
539
+ end
540
+ "#{fr} (#{year})"
506
541
  end
507
542
 
508
543
  def create_meeting_docids(en_id)
509
- fr_id = en_id.sub(/(\d+)th/, '\1e').sub("meeting", "réunion")
544
+ fr_id = en_id.sub(/(\d+)(?:st|nd|rd|th)/, '\1e').sub("Meeting", "Réunion")
510
545
  [
511
546
  make_docid(id: en_id, type: "BIPM", primary: true, language: "en", script: "Latn"),
512
547
  make_docid(id: fr_id, type: "BIPM", primary: true, language: "fr", script: "Latn"),
548
+ make_docid(id: "#{en_id} / #{fr_id}", type: "BIPM", primary: true),
513
549
  ]
514
550
  end
515
551
 
516
- #
517
- # Create French document ID
518
- #
519
- # @param [String] en_id English document ID
520
- #
521
- # @return [RelatonBib::DocumentIdentifier] french document ID
522
- #
523
- # def create_docid_fr(en_id)
524
- # tr = TRANSLATIONS.detect { |_, v| en_id.include? v }
525
- # id = tr ? en_id.sub(tr[1], tr[0]) : en_id
526
- # make_docid(id: id, type: "BIPM", primary: true, language: "fr", script: "Latn")
527
- # end
528
-
529
552
  #
530
553
  # Create doucment ID
531
554
  #
@@ -87,9 +87,11 @@ module RelatonBipm
87
87
  #
88
88
  # @return [Boolean] true if the two Id objects are equal
89
89
  #
90
- def ==(other)
90
+ def ==(other) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
91
91
  other_hash = other.is_a?(Id) ? other.to_hash : normalize_hash(other)
92
92
  hash = to_hash
93
+ hash.delete(:number) if other_hash[:number].nil? && hash[:number] == "1"
94
+ other_hash.delete(:number) if hash[:number].nil? && other_hash[:number] == "1"
93
95
  hash.delete(:year) unless other_hash[:year]
94
96
  other_hash.delete(:year) unless hash[:year]
95
97
  hash.delete(:lang) unless other_hash[:lang]
@@ -33,8 +33,6 @@ module RelatonBipm
33
33
  item = ArticleParser.parse path
34
34
  file = "#{item.docidentifier.first.id.downcase.gsub(' ', '-')}.#{@data_fetcher.ext}"
35
35
  out_path = File.join(@data_fetcher.output, file)
36
- @data_fetcher.index[[item.docidentifier.first.id]] = out_path
37
- @data_fetcher.index_new.add_or_update [item.docidentifier.first.id], out_path
38
36
  key = Id.new(item.docidentifier.first.id).to_hash
39
37
  @data_fetcher.index2.add_or_update key, out_path
40
38
  @data_fetcher.write_file out_path, item
@@ -78,8 +76,6 @@ module RelatonBipm
78
76
  )
79
77
  file = "#{id.downcase.gsub(' ', '-')}.#{@data_fetcher.ext}"
80
78
  path = File.join(@data_fetcher.output, file)
81
- @data_fetcher.index[[id]] = path
82
- @data_fetcher.index_new.add_or_update [id], path
83
79
  @data_fetcher.index2.add_or_update Id.new(id).to_hash, path
84
80
  @data_fetcher.write_file path, item
85
81
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.14.6".freeze
2
+ VERSION = "1.14.7".freeze
3
3
  end
data/relaton_bipm.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
34
34
 
35
35
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
36
36
 
37
- spec.add_dependency "faraday", "~> 1.0"
37
+ spec.add_dependency "faraday", "~> 2.7.0"
38
38
  spec.add_dependency "mechanize", "~> 2.8.0"
39
39
  spec.add_dependency "parslet", "~> 2.0.0"
40
40
  spec.add_dependency "relaton-bib", "~> 1.14.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bipm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.6
4
+ version: 1.14.7
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: 2023-05-03 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: 2.7.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: 2.7.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mechanize
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -175,7 +175,7 @@ licenses:
175
175
  metadata:
176
176
  homepage_uri: https://github.com/relaton/relaton-bipm
177
177
  source_code_uri: https://github.com/relaton/relaton-bipm
178
- post_install_message:
178
+ post_install_message:
179
179
  rdoc_options: []
180
180
  require_paths:
181
181
  - lib
@@ -190,8 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.4.9
194
- signing_key:
193
+ rubygems_version: 3.3.26
194
+ signing_key:
195
195
  specification_version: 4
196
196
  summary: 'RelatonBipm: retrieve BIPM Standards for bibliographic use using the BibliographicItem
197
197
  model'