relaton-bipm 1.11.8 → 1.11.9

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: d9f54a255e430e5079420ef5a4073baa326b29cbb3d687406b9c940fd1ad7406
4
- data.tar.gz: 2e26e487ef00db549f1fa10075c27de47c520b38544c3e408274299805aae4ff
3
+ metadata.gz: e11a60de824e9077a64e3b8ac31a578a9c5255a41ea8175d61b42186b6ef9eb6
4
+ data.tar.gz: a179822bd35ada0812119e508b756c5a4edba82bf34352d2ba9c4fff4a9b4be6
5
5
  SHA512:
6
- metadata.gz: b20367d802b0f7b46794cc28d149c411ec8f7ec88af5b22195b465051eb28fcd4ae5f49fdcf41a78a8651f79d197a4a96f861ab126801563dfaf8c089b0e5c06
7
- data.tar.gz: c06515b865194bf25520c942025419a0502eb03bff3bc80c9ebb649c91634210cf89afc239319278d81f105cb2af726349ce0c9c4aebfc3ff72c0f6bed90d261
6
+ metadata.gz: bd9b8ced31703af3b6ceedefc793da7f1d009750f2fc8c75292690244fd3b2c426ea1d6e39ff358425031fa35d96db4db81fa48c03766448186fd2e990fe7827
7
+ data.tar.gz: 5f719b30f70141397bffda7d72e1add612099b05cc36daef4fcaa3143c2513a7a2750d39c084a92f30c1fe70438fa5e651e8973feb90d60c97d50bede3fd141d
data/README.adoc CHANGED
@@ -33,6 +33,61 @@ Or install it yourself as:
33
33
 
34
34
  === Search for a standard using keywords
35
35
 
36
+ ==== References for Si-Brochure documents
37
+
38
+ `BIPM {DOCUMENT_NAME}`
39
+
40
+ Allowed document names are:
41
+
42
+ - guide-ccem-ampere-realization
43
+ - guide-ccl-metre-realization-1
44
+ - guide-ccl-metre-realization-2
45
+ - guide-ccl-metre-realization-3
46
+ - guide-ccm-kilogram-calibration
47
+ - guide-ccm-kilogram-dissemination
48
+ - mep-ampere-definition
49
+ - mep-candela-definition
50
+ - mep-candela-rapport
51
+ - mep-kelvin-absolute-uncertainty
52
+ - mep-kelvin-absolute
53
+ - mep-kelvin-definition
54
+ - mep-kelvin-lt-johnson-noise
55
+ - mep-kelvin-relative
56
+ - mep-kilogram-definition
57
+ - mep-metre-definition
58
+ - mep-mole-definition
59
+ - mep-second-definition
60
+ - si-brochure
61
+ - sib-a4
62
+
63
+ ==== Reference structire for Metrologia documents
64
+
65
+ `BIPM Metrologia {JOURNAL} {VOLUME} {ISSUE} {ARTICLE}`
66
+
67
+ - `{JOURNAL}` - number of journal, required
68
+ - `{VOLUME}` - number of volume, optional
69
+ - `{ISSUE}` - number of issue, optional
70
+ - `{ARTICLE}` - number of article, optional
71
+
72
+ ==== Reference structures for CCTF (CCDS), CGMP, CIPM documents
73
+
74
+ - `{BODY} {TYPE} {YEAR}-{2_DIGITS_NUMBER}`
75
+ - `{BODY} {TYPE} {NUMBER} ({YEAR})` or `{BODY} {TYPE} {NUMBER} {YEAR}`
76
+ - `{BODY} {TYPE} {MEETING_NUMBER}-{2_DIGITS_NUMBER}`
77
+ - `{BODY} {TYPE} ({YEAR})` or `{BODY} {TYPE} {YEAR}` - in case only one Resolution/Decision/Declaration/Recommendation is available for the year
78
+ - `{BODY} Meeting {MEETING_NUMBER}` or French version `{BODY} Réunion {MEETING_NUMBER}`
79
+
80
+ The parts of the structures:
81
+
82
+ - `{BODY}` - could be `CCTF` (or old named `CCDS`), CGMP, or CIMP
83
+ - `{TYPE}` - could be English word: `Resolution`, `Decision`, `Declaration`, `Recommendation`; or French word: `Résolution`, `Décision`, `Déclaration`, `Recommandation`
84
+ - `{YEAR}` - year of Resolution/Decision/Declaration/Recommendation
85
+ - `{NUMBER}` - number of Resolution/Decision/Declaration/Recommendation
86
+ - `{2_DIGITS_NUMBER}` - two digits number of Resolution/Decision/Declaration/Recommendatio with lead zero if needs
87
+ - `{MEETING_NUMBER}` - number of mieeting
88
+
89
+ ==== Examples
90
+
36
91
  [source,ruby]
37
92
  ----
38
93
  require 'relaton_bipm'
@@ -78,7 +133,7 @@ RelatonBipm::BipmBibliography.get "CGPM Resolution 1889"
78
133
  => #<RelatonBipm::BipmBibliographicItem:0x00007ff0d1ffae50
79
134
  ...
80
135
 
81
- # get CIPM decision
136
+ # get CIPM decision by year and decision number
82
137
  RelatonBipm::BipmBibliography.get "CIPM Decision 2012-01"
83
138
  [relaton-bipm] ("CIPM Decision 2012-01") fetching...
84
139
  [relaton-bipm] ("CIPM Decision 2012-01") found CIPM Decision 1 (2012)
@@ -91,6 +146,13 @@ RelatonBipm::BipmBibliography.get "CIPM Decision 1 (2012)"
91
146
  => #<RelatonBipm::BipmBibliographicItem:0x00007fb6b9bbec08
92
147
  ...
93
148
 
149
+ # get CIPM decision by meeting number and decision number
150
+ RelatonBipm::BipmBibliography.get "CIPM Decision 101-01"
151
+ [relaton-bipm] ("CIPM Decision 101-01") fetching...
152
+ [relaton-bipm] ("CIPM Decision 101-01") found CIPM Decision 1 (2012)
153
+ => #<RelatonBipm::BipmBibliographicItem:0x00007f9ef2acc400
154
+ ...
155
+
94
156
  # get CIPM recommendation
95
157
  RelatonBipm::BipmBibliography.get "CIPM Recommendation (1948)"
96
158
  [relaton-bipm] ("CIPM Recommendation (1948)") fetching...
@@ -63,8 +63,8 @@ module RelatonBipm
63
63
  b.doctype doctype if doctype
64
64
  editorialgroup&.to_xml b
65
65
  comment_period&.to_xml b
66
- b.send "si-aspect", si_aspect if si_aspect
67
- b.send "meeting-note", meeting_note if meeting_note
66
+ b.send :"si-aspect", si_aspect if si_aspect
67
+ b.send :"meeting-note", meeting_note if meeting_note
68
68
  structuredidentifier&.to_xml b
69
69
  end
70
70
  end
@@ -76,7 +76,7 @@ module RelatonBipm
76
76
  hash = super
77
77
  hash["comment_period"] = comment_period.to_hash if comment_period
78
78
  hash["si_aspect"] = si_aspect if si_aspect
79
- hash["meeting-note"] = meeting_note if meeting_note
79
+ hash["meeting_note"] = meeting_note if meeting_note
80
80
  hash
81
81
  end
82
82
 
@@ -2,7 +2,7 @@ require "mechanize"
2
2
 
3
3
  module RelatonBipm
4
4
  class BipmBibliography
5
- GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/master/data/".freeze
5
+ GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/master/".freeze
6
6
  IOP_DOMAIN = "https://iopscience.iop.org".freeze
7
7
  SUBSTITUTES = {
8
8
  "Déclaration" => "Declaration",
@@ -52,18 +52,15 @@ module RelatonBipm
52
52
  "#{$2}-#{$1.to_s.rjust(2, '0')}"
53
53
  end
54
54
  SUBSTITUTES.each { |fr, en| rf.sub! fr, en }
55
- path_parts = rf.split.map &:downcase
56
- path_parts.insert(1, "meeting") unless path_parts[1] == "meeting"
57
- url = "#{GH_ENDPOINT}#{path_parts.join '/'}.yaml"
55
+ path = Index.new.search rf
56
+ return unless path
57
+
58
+ url = "#{GH_ENDPOINT}#{path}"
58
59
  resp = agent.get url
59
60
  check_response resp
60
61
  return unless resp.code == "200"
61
62
 
62
- yaml = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0.pre1")
63
- YAML.safe_load(resp.body, permitted_classes: [Date])
64
- else
65
- YAML.safe_load(resp.body, [Date])
66
- end
63
+ yaml = RelatonBipm.parse_yaml resp.body, [Date]
67
64
  bib_hash = HashConverter.hash_to_bib yaml
68
65
  BipmBibliographicItem.new(**bib_hash)
69
66
  end
@@ -0,0 +1,68 @@
1
+ module RelatonBipm
2
+ class Index
3
+ #
4
+ # Initialize index
5
+ #
6
+ def initialize
7
+ read_index_file || get_index_from_gh
8
+ end
9
+
10
+ #
11
+ # Search index entry
12
+ #
13
+ # @param [String] ref reference
14
+ #
15
+ # @return [String] path to document file
16
+ #
17
+ def search(ref)
18
+ @index.detect { |key, _| key.include? ref }&.last
19
+ end
20
+
21
+ private
22
+
23
+ #
24
+ # Create dir if need and return path to index file
25
+ #
26
+ # @return [String] path to index file
27
+ #
28
+ def path
29
+ @path ||= begin
30
+ dir = File.join Dir.home, ".relaton", "bipm"
31
+ FileUtils.mkdir_p dir unless Dir.exist? dir
32
+ File.join dir, "index.yaml"
33
+ end
34
+ end
35
+
36
+ #
37
+ # Read index from file if it exists and not outdated
38
+ #
39
+ # @return [Hash, nil] index content
40
+ #
41
+ def read_index_file
42
+ return if !File.exist?(path) || File.ctime(path).to_date < Date.today
43
+
44
+ @index = RelatonBipm.parse_yaml File.read(path, encoding: "UTF-8")
45
+ end
46
+
47
+ #
48
+ # Save index to file
49
+ #
50
+ # @return [<Type>] <description>
51
+ #
52
+ def save_index_file
53
+ File.write path, @index.to_yaml, encoding: "UTF-8"
54
+ end
55
+
56
+ #
57
+ # Get index from a GitHub repository
58
+ #
59
+ # @return [Hash] index content
60
+ #
61
+ def get_index_from_gh # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
62
+ resp = Zip::InputStream.new URI("#{BipmBibliography::GH_ENDPOINT}index.zip").open
63
+ zip = resp.get_next_entry
64
+ @index = RelatonBipm.parse_yaml zip.get_input_stream.read
65
+ save_index_file
66
+ end
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.11.8".freeze
2
+ VERSION = "1.11.9".freeze
3
3
  end
data/lib/relaton_bipm.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "zip"
2
+ require "fileutils"
1
3
  require "relaton_bib"
2
4
  require "relaton_bipm/version"
3
5
  require "relaton_bipm/editorial_group"
@@ -11,16 +13,35 @@ require "relaton_bipm/bipm_bibliographic_item"
11
13
  require "relaton_bipm/bipm_bibliography"
12
14
  require "relaton_bipm/hash_converter"
13
15
  require "relaton_bipm/xml_parser"
16
+ require "relaton_bipm/index"
14
17
 
15
18
  module RelatonBipm
16
19
  class Error < StandardError; end
17
20
 
18
21
  # Returns hash of XML reammar
19
22
  # @return [String]
20
- def self.grammar_hash
23
+ def grammar_hash
21
24
  gem_path = File.expand_path "..", __dir__
22
25
  grammars_path = File.join gem_path, "grammars", "*"
23
26
  grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
24
27
  Digest::MD5.hexdigest grammars
25
28
  end
29
+
30
+ #
31
+ # Parse yaml content
32
+ #
33
+ # @param [String] yaml content
34
+ #
35
+ # @return [Hash] data
36
+ #
37
+ def parse_yaml(yaml, classes = [])
38
+ # Newer versions of Psych uses the `permitted_classes:` parameter
39
+ if YAML.method(:safe_load).parameters.map(&:last).include? :permitted_classes
40
+ YAML.safe_load(yaml, permitted_classes: classes)
41
+ else
42
+ YAML.safe_load(yaml, classes)
43
+ end
44
+ end
45
+
46
+ extend self
26
47
  end
data/relaton_bipm.gemspec CHANGED
@@ -45,5 +45,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
45
45
 
46
46
  spec.add_dependency "mechanize", "~> 2.8.0"
47
47
  spec.add_dependency "relaton-bib", "~> 1.11.0"
48
+ spec.add_dependency "rubyzip", "~> 2.3.0"
48
49
  spec.add_dependency "serrano", "~> 1.0"
49
50
  end
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.11.8
4
+ version: 1.11.9
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-06-03 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.11.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubyzip
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.3.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.3.0
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: serrano
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +199,7 @@ files:
185
199
  - lib/relaton_bipm/document_relation.rb
186
200
  - lib/relaton_bipm/editorial_group.rb
187
201
  - lib/relaton_bipm/hash_converter.rb
202
+ - lib/relaton_bipm/index.rb
188
203
  - lib/relaton_bipm/processor.rb
189
204
  - lib/relaton_bipm/structured_identifier.rb
190
205
  - lib/relaton_bipm/version.rb