relaton-bsi 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_bsi/bsi_bibliography.rb +34 -27
- data/lib/relaton_bsi/hit_collection.rb +50 -7
- data/lib/relaton_bsi/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: e6526b98460dccb16324ffdbc6cea2309b8e1eda6b5c06ed8272c4bae289b5fa
|
4
|
+
data.tar.gz: 4d64f8b75a735c5ccfbacf3f03816b62ebd22ea4cb2d564ebbb67b87643fbaa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b640a7761c3eab1336b54904b31ce8b68477b1736bce1ec2d5b1f4775f8f2c31d9b35e9608e48a922c957e62000c4860f1fecfcb743d6602f2becc5446a7ebab
|
7
|
+
data.tar.gz: 1f80f9e3e3a9a0f613bf239e57b53bb8c9a0e189e841d11d9668a479d959eaa1accbd78a8e6ede2e1a78103a04d2658417eed19ab92712ac693ae1921aafe10d
|
@@ -35,7 +35,7 @@ module RelatonBsi
|
|
35
35
|
def get(code, year = nil, opts = {})
|
36
36
|
# y = code.split(":")[1]
|
37
37
|
year ||= code_parts(code)[:year]
|
38
|
-
ret =
|
38
|
+
ret = bib_get(code, year, opts)
|
39
39
|
return nil if ret.nil?
|
40
40
|
|
41
41
|
ret = ret.to_most_recent_reference unless year || opts[:keep_year]
|
@@ -43,10 +43,27 @@ module RelatonBsi
|
|
43
43
|
ret
|
44
44
|
end
|
45
45
|
|
46
|
+
#
|
47
|
+
# Destruct code to its parts.
|
48
|
+
#
|
49
|
+
# @param [String] code document identifier
|
50
|
+
#
|
51
|
+
# @return [MatchData] parts of the code
|
52
|
+
#
|
53
|
+
def code_parts(code)
|
54
|
+
%r{
|
55
|
+
^(?:BSI\s)?(?<code>(?:[A-Z]+\s)*[^:\s+]+)
|
56
|
+
(?::(?<year>\d{4}))?
|
57
|
+
(?:\+(?<a>[^:\s]+)(?::(?<y>\d{4}))?)?
|
58
|
+
(?:\s(?<rest>.+))?
|
59
|
+
}x.match code
|
60
|
+
end
|
61
|
+
|
46
62
|
private
|
47
63
|
|
48
64
|
def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
|
49
|
-
|
65
|
+
y = code_parts(code)[:year]
|
66
|
+
id = year && !y ? "#{code}:#{year}" : code
|
50
67
|
warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
|
51
68
|
"The code must be exactly like it is on the standards website."
|
52
69
|
unless missed_years.empty?
|
@@ -65,29 +82,19 @@ module RelatonBsi
|
|
65
82
|
nil
|
66
83
|
end
|
67
84
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
85
|
+
#
|
86
|
+
# Search for a BSI standard.
|
87
|
+
#
|
88
|
+
# @param [String] code the BSI standard Code to look up
|
89
|
+
#
|
90
|
+
# @return [RelatonBsi::HitCollection] a collection of hits
|
91
|
+
#
|
92
|
+
def search_filter(code)
|
93
|
+
cp = code_parts code
|
72
94
|
warn "[relaton-bsi] (\"#{code}\") fetching..."
|
73
|
-
return [] unless
|
74
|
-
|
75
|
-
result = search(code)
|
76
|
-
result.select do |i|
|
77
|
-
# %r{^(?<code2>[^:]+)} =~ i.hit[:code]
|
78
|
-
cp2 = code_parts i.hit[:code]
|
79
|
-
cp2[:code] == cp1[:code] && (!cp1[:a] || cp2[:a] == cp1[:a]) &&
|
80
|
-
(!cp1[:y] || cp2[:y] == cp1[:y])
|
81
|
-
end
|
82
|
-
end
|
95
|
+
return [] unless cp
|
83
96
|
|
84
|
-
|
85
|
-
%r{
|
86
|
-
^(?:BSI\s)?(?<code>[^:]+)
|
87
|
-
(?::(?<year>\d{4}))?
|
88
|
-
(?:\+(?<a>[^:]+):)?
|
89
|
-
(?::(?<y>\d{4}))?
|
90
|
-
}x.match code
|
97
|
+
search(code).filter_hits!(cp)
|
91
98
|
end
|
92
99
|
|
93
100
|
# Sort through the results from Isobib, fetching them three at a time,
|
@@ -96,10 +103,10 @@ module RelatonBsi
|
|
96
103
|
# Only expects the first page of results to be populated.
|
97
104
|
# Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
|
98
105
|
# If no match, returns any years which caused mismatch, for error reporting
|
99
|
-
def
|
106
|
+
def results_filter(result, year)
|
100
107
|
missed_years = []
|
101
108
|
result.each do |r|
|
102
|
-
|
109
|
+
pyear = code_parts(r.hit[:code])[:year]
|
103
110
|
if !year || year == pyear
|
104
111
|
ret = r.fetch
|
105
112
|
return { ret: ret } if ret
|
@@ -110,9 +117,9 @@ module RelatonBsi
|
|
110
117
|
{ years: missed_years }
|
111
118
|
end
|
112
119
|
|
113
|
-
def
|
120
|
+
def bib_get(code, year, _opts)
|
114
121
|
result = search_filter(code) || return
|
115
|
-
ret =
|
122
|
+
ret = results_filter(result, year)
|
116
123
|
if ret[:ret]
|
117
124
|
warn "[relaton-bsi] (\"#{code}\") found #{ret[:ret].docidentifier.first&.id}"
|
118
125
|
ret[:ret]
|
@@ -8,8 +8,12 @@ module RelatonBsi
|
|
8
8
|
class HitCollection < RelatonBib::HitCollection
|
9
9
|
DOMAIN = "https://shop.bsigroup.com"
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
11
|
+
#
|
12
|
+
# Initialize a new HitCollection.
|
13
|
+
#
|
14
|
+
# @param ref [String] reference
|
15
|
+
# @param year [String] year
|
16
|
+
#
|
13
17
|
def initialize(ref, year = nil)
|
14
18
|
super ref, year
|
15
19
|
config = Algolia::Search::Config.new(
|
@@ -19,19 +23,39 @@ module RelatonBsi
|
|
19
23
|
client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
|
20
24
|
index = client.init_index "shopify_products"
|
21
25
|
resp = index.search text # , facetFilters: "product_type:standard"
|
22
|
-
@array =
|
26
|
+
@array = create_hits resp[:hits]
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Filter the search results for a BSI standard.
|
31
|
+
#
|
32
|
+
# @param [MatchData] code_parts parts of document identifier
|
33
|
+
#
|
34
|
+
# @return [self] filtered search results
|
35
|
+
#
|
36
|
+
def filter_hits!(code_parts)
|
37
|
+
hits = filter code_parts
|
38
|
+
hits = filter code_parts, skip_rest: true if hits.empty?
|
39
|
+
hits = filter code_parts, drop_amd: true if hits.empty?
|
40
|
+
@array = hits
|
41
|
+
self
|
23
42
|
end
|
24
43
|
|
25
44
|
private
|
26
45
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
46
|
+
#
|
47
|
+
# Create hits from search results.
|
48
|
+
#
|
49
|
+
# @param hits [Array<Hash>] search results
|
50
|
+
#
|
51
|
+
# @return [Array<RelatonBsi::Hit>] hits
|
52
|
+
#
|
53
|
+
def create_hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
30
54
|
hits.each_with_object([]) do |h, obj|
|
31
55
|
next unless h[:meta][:global][:publishedDate]
|
32
56
|
|
33
57
|
code = h[:meta][:global][:primaryDesignator]
|
34
|
-
.sub(/\s(?:LOOSELEAF|\(A5 LAMINATED\)|-\
|
58
|
+
.sub(/\s?(?:LOOSELEAF|\(A5 LAMINATED\)|-\s?TC$)/, "")
|
35
59
|
obj << Hit.new(
|
36
60
|
{
|
37
61
|
code: code,
|
@@ -46,5 +70,24 @@ module RelatonBsi
|
|
46
70
|
)
|
47
71
|
end.sort_by { |h| h.hit[:date] }.reverse
|
48
72
|
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Select hits that match the document identifier.
|
76
|
+
#
|
77
|
+
# @param [MatchData] code_parts parts of document identifier
|
78
|
+
# @param [Boolean] drop_amd drop amendments and corrigendums
|
79
|
+
# @param [Boolean] skip_rest skip rest suffix of document identifier
|
80
|
+
#
|
81
|
+
def filter(code_parts, drop_amd: false, skip_rest: false) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
82
|
+
@array.select do |i|
|
83
|
+
code = drop_amd ? i.hit[:code].sub(/\+[AC]\d+.*$/, "") : i.hit[:code]
|
84
|
+
cp = BsiBibliography.code_parts code
|
85
|
+
match = cp[:code] == code_parts[:code] && cp[:a] == code_parts[:a] &&
|
86
|
+
(!code_parts[:y] || cp[:y] == code_parts[:y]) &&
|
87
|
+
(skip_rest || cp[:rest] == code_parts[:rest])
|
88
|
+
i.hit[:code] = code if drop_amd && match
|
89
|
+
match
|
90
|
+
end
|
91
|
+
end
|
49
92
|
end
|
50
93
|
end
|
data/lib/relaton_bsi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bsi
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|