relaton-bsi 1.9.1 → 1.9.5

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: 762ff6b45033ac0a1d992a71e317857a198bebf26078a5018eb7f66932a3b13a
4
- data.tar.gz: f57772a8f6a38508d52275df9371f734a62aa6ab2e937f4f1796ee91654a86cc
3
+ metadata.gz: 9db2a5ff65039b9e7bbda2507f116444d0f0cccc7919da1e3be8d735c94d5324
4
+ data.tar.gz: 903b68e85f928546ae715b4c0f88cf602e31717d38a39e8f7455df8d4c03ef31
5
5
  SHA512:
6
- metadata.gz: fcc4a7e94e32c77c4e5ac26811797db97a57616af9c2867a299c1b155a7209c302f24e372e5bae5dee7287e59ac5e5a8bf08ffafd068d2fbc88b74784ac1d14d
7
- data.tar.gz: a688c0ef854eaa91003b9728ed46e54498b17a75f877a84418862fa1d960cfec5e501bb56661ea545fcdf6877f465d77c2fccc985ed0968a29cb96a7f0413910
6
+ metadata.gz: bb7f32531e7aedc5eb0d6499a31cabe1d642809f8b7f324e44bd3ea3af9e751415eb1f06fdb0cf003a3499b543fa202a046e9fce54e16965f39e6ca36c1b4ffd
7
+ data.tar.gz: d943a7d57ab744e350eb56bd325b7df2e2ea86c513032899b208aa8e9600a0a48c22a76b6cb887885f85edceb545bbe018a855870312e18a15ebd973a03b006a
data/.rubocop.yml CHANGED
@@ -2,6 +2,8 @@
2
2
  # https://github.com/riboseinc/oss-guides
3
3
  # All project-specific additions and overrides should be specified in this file.
4
4
 
5
+ require: rubocop-rails
6
+
5
7
  inherit_from:
6
8
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
7
9
  AllCops:
data/README.adoc CHANGED
@@ -124,11 +124,10 @@ item.to_xml bibdata: true
124
124
  </bibdata>"
125
125
  ----
126
126
 
127
- === Get code, and year
127
+ === Get standard by code and year
128
128
  [source,ruby]
129
129
  ----
130
- RelatonBsi::BsiBibliographicItem RelatonBsi::BsiBibliography
131
- [7] pry(main)> RelatonBsi::BsiBibliography.get "BS EN ISO 8848:2021"
130
+ RelatonBsi::BsiBibliography.get "BS EN ISO 8848:2021"
132
131
  [relaton-bsi] ("BS EN ISO 8848:2021") fetching...
133
132
  [relaton-bsi] ("BS EN ISO 8848:2021") found BS EN ISO 8848:2021
134
133
  => #<RelatonBsi::BsiBibliographicItem:0x007feb14814ca8
@@ -24,17 +24,21 @@ module RelatonBsi
24
24
  raise RelatonBib::RequestError, e.message
25
25
  end
26
26
 
27
+ #
27
28
  # @param code [String] the BSI standard Code to look up
28
29
  # @param year [String] the year the standard was published (optional)
29
- # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
30
+ # @param opts [Hash] options
31
+ # @option opts [Boolean] :all_parts if all-parts reference is required
32
+ # @option opts [Boolean] :no_year if last published document is required
33
+ #
30
34
  # @return [String] Relaton XML serialisation of reference
31
- def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
32
- c, y = code.split ':'
33
- year ||= y
34
- ret = bib_get1(c, year, opts)
35
+ def get(code, year = nil, opts = {})
36
+ # y = code.split(":")[1]
37
+ year ||= code_parts(code)[:year]
38
+ ret = bib_get1(code, year, opts)
35
39
  return nil if ret.nil?
36
40
 
37
- # ret = ret.to_most_recent_reference unless year || opts[:keep_year]
41
+ ret = ret.to_most_recent_reference unless year || opts[:keep_year]
38
42
  # ret = ret.to_all_parts if opts[:all_parts]
39
43
  ret
40
44
  end
@@ -44,35 +48,48 @@ module RelatonBsi
44
48
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
45
49
  id = year ? "#{code}:#{year}" : code
46
50
  warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
47
- "The code must be exactly like it is on the standards website."
51
+ "The code must be exactly like it is on the standards website."
48
52
  unless missed_years.empty?
49
- warn "[relaton-bsi] (There was no match for #{year}, though there were matches "\
50
- "found for #{missed_years.join(', ')}.)"
53
+ warn "[relaton-bsi] (There was no match for #{year}, though there "\
54
+ "were matches found for #{missed_years.join(', ')}.)"
51
55
  end
52
56
  # if /\d-\d/.match? code
53
- # warn "[relaton-bsi] The provided document part may not exist, or the document "\
54
- # "may no longer be published in parts."
57
+ # warn "[relaton-bsi] The provided document part may not exist, or "\
58
+ # "the document may no longer be published in parts."
55
59
  # else
56
- # warn "[relaton-bsi] If you wanted to cite all document parts for the reference, "\
57
- # "use \"#{code} (all parts)\".\nIf the document is not a standard, "\
58
- # "use its document type abbreviation (TS, TR, PAS, Guide)."
60
+ # warn "[relaton-bsi] If you wanted to cite all document parts for "\
61
+ # "the reference, use \"#{code} (all parts)\".\nIf the document "\
62
+ # "is not a standard, use its document type abbreviation (TS, TR, "\
63
+ # "PAS, Guide)."
59
64
  # end
60
65
  nil
61
66
  end
62
67
 
63
68
  def search_filter(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
64
- # %r{^BSI\s(?<code1>[^:]+)} =~ code
65
- code1 = code.sub(/^BSI\s/, "")
69
+ # %r{^(?:BSI\s)?(?<code1>[^:]+)} =~ code
70
+ # %r{^(?<code1>[^:]+)} =~ code.sub(/^BSI\s/, "")
71
+ cp1 = code_parts code
66
72
  warn "[relaton-bsi] (\"#{code}\") fetching..."
67
- return [] unless code1
73
+ return [] unless cp1
68
74
 
69
75
  result = search(code)
70
76
  result.select do |i|
71
- %r{^(?<code2>[^:]+)} =~ i.hit[:code]
72
- code2.include?(code1)
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])
73
81
  end
74
82
  end
75
83
 
84
+ def code_parts(code)
85
+ %r{
86
+ ^(?:BSI\s)?(?<code>[^:]+)
87
+ (?::(?<year>\d{4}))?
88
+ (?:\+(?<a>[^:]+):)?
89
+ (?::(?<y>\d{4}))?
90
+ }x.match code
91
+ end
92
+
76
93
  # Sort through the results from Isobib, fetching them three at a time,
77
94
  # and return the first result that matches the code,
78
95
  # matches the year (if provided), and which # has a title (amendments do not).
@@ -8,16 +8,14 @@ module RelatonBsi
8
8
  class HitCollection < RelatonBib::HitCollection
9
9
  DOMAIN = "https://shop.bsigroup.com"
10
10
 
11
- # @return [Mechanize]
12
- # attr_reader :agent
13
-
14
11
  # @param ref [String]
15
12
  # @param year [String]
16
13
  def initialize(ref, year = nil)
17
14
  super ref, year
18
- # @agent = Mechanize.new
19
- # resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
20
- config = Algolia::Search::Config.new(application_id: "575YE157G9", api_key: "a057b4e74099445df2eddb7940828a10")
15
+ config = Algolia::Search::Config.new(
16
+ application_id: "575YE157G9",
17
+ api_key: "a057b4e74099445df2eddb7940828a10",
18
+ )
21
19
  client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
22
20
  index = client.init_index "shopify_products"
23
21
  resp = index.search text # , facetFilters: "product_type:standard"
@@ -28,11 +26,13 @@ module RelatonBsi
28
26
 
29
27
  # @param hits [Array<Hash>]
30
28
  # @return [Array<RelatonBsi::Hit>]
31
- def hits(hits) # rubocop:disable Metrics/MethodLength
29
+ def hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
32
30
  hits.map do |h|
31
+ code = h[:meta][:global][:primaryDesignator]
32
+ .sub(/\s(?:LOOSELEAF|\(A5 LAMINATED\)|-\sTC$)/, "")
33
33
  Hit.new(
34
34
  {
35
- code: h[:meta][:global][:primaryDesignator],
35
+ code: code,
36
36
  title: h[:title],
37
37
  url: h[:handle],
38
38
  date: h[:meta][:global][:publishedDate],
@@ -42,7 +42,7 @@ module RelatonBsi
42
42
  doctype: h[:product_type],
43
43
  }, self
44
44
  )
45
- end
45
+ end.sort_by { |h| h.hit[:date] }.reverse
46
46
  end
47
47
  end
48
48
  end
@@ -118,9 +118,9 @@ module RelatonBsi
118
118
  # @param docid [String]
119
119
  # @param data [Hash]
120
120
  # @return [Array<RelatonBib::DocumentIdentifier>]
121
- def fetch_docid(docid, data)
121
+ def fetch_docid(docid, data) # rubocop:disable Metrics/AbcSize
122
122
  ids = [{ type: "BSI", id: docid }]
123
- if data.any?
123
+ if data.any? && data["variants"]["edges"][0]["node"]["isbn"]
124
124
  isbn = data["variants"]["edges"][0]["node"]["isbn"]["value"]
125
125
  ids << { type: "ISBN", id: isbn }
126
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBsi
4
- VERSION = "1.9.1"
4
+ VERSION = "1.9.5"
5
5
  end
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.9.1
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-03 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml