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 +4 -4
- data/lib/relaton_cen/cen_bibliography.rb +30 -13
- data/lib/relaton_cen/hit_collection.rb +16 -2
- data/lib/relaton_cen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393deb797844179a0b7330a483211e0cc53f2634a2149f9c3a30ab9f11203d21
|
4
|
+
data.tar.gz: 2fe98d3c32dee65865570f8d767ebc2b2fa5ef00f38ac76de203102d164a738b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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 = {})
|
29
|
-
|
30
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
66
|
-
|
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
|
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)
|
data/lib/relaton_cen/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|