relaton-cen 1.11.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: c2db8abca05c34c25fec74fa73946b825629b6e6dcc5f37817898cf26b34d04d
4
- data.tar.gz: 113f18448ece3873bf307dad1768025ad5250ed89cf0396d939f2a263606ea6b
3
+ metadata.gz: 393deb797844179a0b7330a483211e0cc53f2634a2149f9c3a30ab9f11203d21
4
+ data.tar.gz: 2fe98d3c32dee65865570f8d767ebc2b2fa5ef00f38ac76de203102d164a738b
5
5
  SHA512:
6
- metadata.gz: 3c875c090a73560abcd6f851f1573993f17f6f8630f4613747a4553aeaca1a0ff9988c3c11d6104b52e90cb73ea9426f077daccd20e133793e43e542f5d263eb
7
- data.tar.gz: dfecf61b161dcee9c72d61febd49cda48b8ea90bc75df8c9dfd12e2f4ddf5672b7c0ff1d8f044793f2b557ace7ee8dc86dadd2112985f07ac189335422e70d66
6
+ metadata.gz: f49d0990ce8890b5ec18c2293697683b3bdd0ba23e384a3188276fa69b1a6246bcd1888400af4c676b1afc11472e3ebba6d14fd0d5a0830f77d03eaf0b05fc5a
7
+ data.tar.gz: f0964fba6d839133ba6b51717b777c342af965c272d3a1f478460651e58820a93db112f7f394fa03e04696af906a5518473d953397789663550d0c9abd0b58fc
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonCen
4
- VERSION = "1.11.0"
4
+ VERSION = "1.11.1"
5
5
  end
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.11.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-04-10 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