relaton-cen 1.10.0 → 1.11.1

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: '085f9f31d68845bf7b059f2d72c37108f5c0961326c9180be37158c96c62b7e9'
4
- data.tar.gz: 0eb930c6f94df2cc984c2eaccfccc2b8eeae44f9264436c0bd199a0b2fb3eac7
3
+ metadata.gz: 393deb797844179a0b7330a483211e0cc53f2634a2149f9c3a30ab9f11203d21
4
+ data.tar.gz: 2fe98d3c32dee65865570f8d767ebc2b2fa5ef00f38ac76de203102d164a738b
5
5
  SHA512:
6
- metadata.gz: 1e6b4d320c12948e1286732c8130afedb09c261f1e3852110c8b8c7e706c6fdd0c17d8310e5e29d7e0605ebbfff24deeef36701731f3e270c3d017f0701fed6d
7
- data.tar.gz: 4c625b64b79e94d97e06a7441c1a89c1ba9d6ee3d4c94855e6d468a8d318eb86f62650993c58c840a16790c79160b80a5274d936edf09aacd77eee144782da01
6
+ metadata.gz: f49d0990ce8890b5ec18c2293697683b3bdd0ba23e384a3188276fa69b1a6246bcd1888400af4c676b1afc11472e3ebba6d14fd0d5a0830f77d03eaf0b05fc5a
7
+ data.tar.gz: f0964fba6d839133ba6b51717b777c342af965c272d3a1f478460651e58820a93db112f7f394fa03e04696af906a5518473d953397789663550d0c9abd0b58fc
data/grammars/biblio.rng CHANGED
@@ -209,9 +209,6 @@
209
209
  <zeroOrMore>
210
210
  <ref name="contact"/>
211
211
  </zeroOrMore>
212
- <zeroOrMore>
213
- <ref name="uri"/>
214
- </zeroOrMore>
215
212
  </element>
216
213
  </define>
217
214
  <define name="fullname">
@@ -680,6 +677,9 @@
680
677
  <zeroOrMore>
681
678
  <ref name="extent"/>
682
679
  </zeroOrMore>
680
+ <optional>
681
+ <ref name="bibliographic_size"/>
682
+ </optional>
683
683
  <zeroOrMore>
684
684
  <ref name="accesslocation"/>
685
685
  </zeroOrMore>
@@ -828,6 +828,11 @@
828
828
  <optional>
829
829
  <attribute name="scope"/>
830
830
  </optional>
831
+ <optional>
832
+ <attribute name="primary">
833
+ <data type="boolean"/>
834
+ </attribute>
835
+ </optional>
831
836
  <text/>
832
837
  </element>
833
838
  </define>
@@ -920,9 +925,29 @@
920
925
  <text/>
921
926
  </element>
922
927
  </define>
928
+ <define name="sizevalue">
929
+ <element name="value">
930
+ <attribute name="type"/>
931
+ <text/>
932
+ </element>
933
+ </define>
934
+ <define name="bibliographic_size">
935
+ <element name="size">
936
+ <oneOrMore>
937
+ <ref name="sizevalue"/>
938
+ </oneOrMore>
939
+ </element>
940
+ </define>
923
941
  <define name="extent">
924
942
  <element name="extent">
925
- <ref name="BibItemLocality"/>
943
+ <choice>
944
+ <zeroOrMore>
945
+ <ref name="locality"/>
946
+ </zeroOrMore>
947
+ <zeroOrMore>
948
+ <ref name="localityStack"/>
949
+ </zeroOrMore>
950
+ </choice>
926
951
  </element>
927
952
  </define>
928
953
  <define name="series">
data/grammars/isodoc.rng CHANGED
@@ -152,9 +152,7 @@
152
152
  <data type="boolean"/>
153
153
  </attribute>
154
154
  </optional>
155
- <oneOrMore>
156
- <ref name="PureTextElement"/>
157
- </oneOrMore>
155
+ <ref name="XrefBody"/>
158
156
  </element>
159
157
  </define>
160
158
  <define name="erefType">
@@ -188,6 +186,42 @@
188
186
  <ref name="PureTextElement"/>
189
187
  </oneOrMore>
190
188
  </define>
189
+ <define name="localityStack">
190
+ <element name="localityStack">
191
+ <optional>
192
+ <attribute name="connective">
193
+ <choice>
194
+ <value>and</value>
195
+ <value>or</value>
196
+ <value>from</value>
197
+ <value>to</value>
198
+ <value/>
199
+ </choice>
200
+ </attribute>
201
+ </optional>
202
+ <zeroOrMore>
203
+ <ref name="locality"/>
204
+ </zeroOrMore>
205
+ </element>
206
+ </define>
207
+ <define name="sourceLocalityStack">
208
+ <element name="sourceLocalityStack">
209
+ <optional>
210
+ <attribute name="connective">
211
+ <choice>
212
+ <value>and</value>
213
+ <value>or</value>
214
+ <value>from</value>
215
+ <value>to</value>
216
+ <value/>
217
+ </choice>
218
+ </attribute>
219
+ </optional>
220
+ <zeroOrMore>
221
+ <ref name="sourceLocality"/>
222
+ </zeroOrMore>
223
+ </element>
224
+ </define>
191
225
  <define name="ul">
192
226
  <element name="ul">
193
227
  <attribute name="id">
@@ -1098,6 +1132,16 @@
1098
1132
  </define>
1099
1133
  </include>
1100
1134
  <!-- end overrides -->
1135
+ <define name="image" combine="choice">
1136
+ <element name="svg">
1137
+ <oneOrMore>
1138
+ <choice>
1139
+ <text/>
1140
+ <ref name="AnyElement"/>
1141
+ </choice>
1142
+ </oneOrMore>
1143
+ </element>
1144
+ </define>
1101
1145
  <define name="MultilingualRenderingType">
1102
1146
  <choice>
1103
1147
  <value>common</value>
@@ -2631,4 +2675,30 @@
2631
2675
  </zeroOrMore>
2632
2676
  </element>
2633
2677
  </define>
2678
+ <define name="XrefBody">
2679
+ <zeroOrMore>
2680
+ <ref name="XrefTarget"/>
2681
+ </zeroOrMore>
2682
+ <oneOrMore>
2683
+ <ref name="PureTextElement"/>
2684
+ </oneOrMore>
2685
+ </define>
2686
+ <define name="XrefTarget">
2687
+ <element name="location">
2688
+ <attribute name="target">
2689
+ <data type="string">
2690
+ <param name="pattern">\i\c*|\c+#\c+</param>
2691
+ </data>
2692
+ </attribute>
2693
+ <attribute name="connective">
2694
+ <choice>
2695
+ <value>and</value>
2696
+ <value>or</value>
2697
+ <value>from</value>
2698
+ <value>to</value>
2699
+ <value/>
2700
+ </choice>
2701
+ </attribute>
2702
+ </element>
2703
+ </define>
2634
2704
  </grammar>
@@ -14,8 +14,8 @@ module RelatonCen
14
14
  # @param text [String]
15
15
  # @return [RelatonCen::HitCollection]
16
16
  def search(text, year = nil)
17
- /^C?EN\s(?<code>.+)/ =~ text
18
- HitCollection.new code, year
17
+ # /^C?EN\s(?<code>.+)/ =~ text
18
+ HitCollection.new text, year
19
19
  rescue Mechanize::ResponseCodeError => e
20
20
  raise RelatonBib::RequestError, e.message
21
21
  end
@@ -25,12 +25,26 @@ module RelatonCen
25
25
  # @param opts [Hash] options; restricted to :all_parts if all-parts
26
26
  # reference is required
27
27
  # @return [RelatonBib::BibliographicItem, nil]
28
- def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
29
- code1, year1 = code.split ":"
30
- code = code1
31
- year ||= year1
28
+ def get(code, year = nil, opts = {})
29
+ code_parts = code_to_parts code
30
+ year ||= code_parts[:year] if code_parts
32
31
 
33
- bib_get1(code, year, opts)
32
+ bib_get(code, year, opts)
33
+ end
34
+
35
+ #
36
+ # Decopmposes a CEN standard code into its parts.
37
+ #
38
+ # @param [String] code the CEN standard code to decompose
39
+ #
40
+ # @return [MatchData] the decomposition of the code
41
+ #
42
+ def code_to_parts(code)
43
+ %r{^
44
+ (?<code>[^:-]+)(?:-(?<part>\d+))?
45
+ (?::(?<year>\d{4}))?
46
+ (?:\+(?<amd>[A-Z]\d+)(?:(?<amy>\d{4}))?)?
47
+ }x.match code
34
48
  end
35
49
 
36
50
  private
@@ -38,10 +52,10 @@ module RelatonCen
38
52
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
39
53
  id = year ? "#{code}:#{year}" : code
40
54
  warn "[relaton-cen] WARNING: no match found online for #{id}. "\
41
- "The code must be exactly like it is on the standards website."
55
+ "The code must be exactly like it is on the standards website."
42
56
  unless missed_years.empty?
43
57
  warn "[relaton-cen] (There was no match for #{year}, though there "\
44
- "were matches found for #{missed_years.join(', ')}.)"
58
+ "were matches found for #{missed_years.join(', ')}.)"
45
59
  end
46
60
  # if /\d-\d/.match? code
47
61
  # warn "[relaton-cen] The provided document part may not exist, or "\
@@ -58,12 +72,15 @@ module RelatonCen
58
72
  # @param code [String]
59
73
  # @return [RelatonCen::HitCollection]
60
74
  def search_filter(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
61
- %r{^C?EN\s(?<code1>[^-:]+)(?:-(?<part1>\d+))?} =~ code
75
+ parts = code_to_parts code
62
76
  warn "[relaton-cen] (\"#{code}\") fetching..."
63
77
  result = search(code)
64
78
  result.select do |i|
65
- %r{^(?<code2>[^:-]+)(?:-(?<part2>\d+))?} =~ i.hit[:code]
66
- code2.include?(code1) && (!part1 || part1 = part2)
79
+ pts = code_to_parts i.hit[:code]
80
+ parts[:code] == pts[:code] &&
81
+ (!parts[:part] || parts[:part] == pts[:part]) &&
82
+ (!parts[:year] || parts[:year] == pts[:year]) &&
83
+ parts[:amd] == pts[:amd] && (!parts[:amy] || parts[:amy] == pts[:amy])
67
84
  end
68
85
  end
69
86
 
@@ -87,7 +104,7 @@ module RelatonCen
87
104
  { years: missed_years }
88
105
  end
89
106
 
90
- def bib_get1(code, year, _opts)
107
+ def bib_get(code, year, _opts)
91
108
  result = search_filter(code) || return
92
109
  ret = isobib_results_filter(result, year)
93
110
  if ret[:ret]
@@ -29,10 +29,10 @@ module RelatonCen
29
29
 
30
30
  val = case f[:value]
31
31
  when "LANGUAGE_LIST" then 0
32
- when "STAND_REF" then ref
32
+ when "STAND_REF" then CGI.escape(ref)
33
33
  else
34
34
  case f[:name]
35
- when "p_request" then "S1-S2-S3-S4-S5-S6-CEN-CLC-"
35
+ when "p_request" then "S1-S2-S3-S4-S5-S6-S7-CEN-CLC-"
36
36
  when "f10" then ""
37
37
  else f[:value]
38
38
  end
@@ -44,10 +44,24 @@ module RelatonCen
44
44
  end.compact.join("&")
45
45
  resp = agent.post form[:action], req_body
46
46
  @array = hits resp
47
+ sort
47
48
  end
48
49
 
49
50
  private
50
51
 
52
+ def sort
53
+ @array.sort! do |a, b|
54
+ ap = CenBibliography.code_to_parts a.hit[:code]
55
+ bp = CenBibliography.code_to_parts b.hit[:code]
56
+ s = ap[:code] <=> bp[:code]
57
+ s = ap[:part].to_s <=> bp[:part].to_s if s.zero?
58
+ s = bp[:year].to_s <=> ap[:year].to_s if s.zero?
59
+ s = ap[:amd].to_s <=> bp[:amd].to_s if s.zero?
60
+ s = ap[:amy].to_s <=> bp[:amy].to_s if s.zero?
61
+ s
62
+ end
63
+ end
64
+
51
65
  # @param resp [Mechanize::Page]
52
66
  # @return [Array<RelatonCen::Hit>]
53
67
  def hits(resp)
@@ -58,7 +58,7 @@ module RelatonCen
58
58
  # @param ref [String]
59
59
  # @return [Array<RelatonBib::DocumentIdentifier>]
60
60
  def fetch_docid(ref)
61
- [RelatonBib::DocumentIdentifier.new(type: "CEN", id: ref)]
61
+ [RelatonBib::DocumentIdentifier.new(type: "CEN", id: ref, primary: true)]
62
62
  end
63
63
 
64
64
  # Fetch status.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonCen
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.1"
5
5
  end
data/relaton_cen.gemspec CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency "webmock"
43
43
 
44
44
  spec.add_dependency "mechanize"
45
- spec.add_dependency "relaton-iso-bib", "~> 1.10.0"
45
+ spec.add_dependency "relaton-iso-bib", "~> 1.11.0"
46
46
 
47
47
  # For more information and examples about making a new gem, checkout our
48
48
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-cen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.1
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-01-30 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.10.0
159
+ version: 1.11.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.10.0
166
+ version: 1.11.0
167
167
  description: 'RelatonCen: retrieve Cenelec Standards for bibliographic use using the
168
168
  IsoBibliographicItem model'
169
169
  email: