relaton-bsi 1.8.2 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,25 @@
1
1
  module RelatonBsi
2
2
  class BsiBibliographicItem < RelatonIsoBib::IsoBibliographicItem
3
3
  TYPES = %w[
4
- specification management-systems-standard code-of-practice guide
5
- method-of-test method-of-specifying vocabulary classification
4
+ british-standard draft-for-development published-document privately-subscribed-standard
5
+ publicly-available-specification flex-standard international-standard technical-specification
6
+ technical-report guide international-workshop-agreement industry-technical-agreement
7
+ standard european-workshop-agreement
6
8
  ].freeze
7
9
 
8
- # @return [String, nil]
9
- attr_reader :price_code
10
-
11
- # @return [Boolean, nil]
12
- attr_reader :cen_processing
10
+ SUBDOCTYPES = %w[specification method-of-test method-of-specifying vocabulary code-of-practice].freeze
13
11
 
14
12
  # @params price_code [String, nil]
15
13
  # @param cen_processing [Boolean, nil]
16
- def initialize(**args)
14
+ def initialize(**args) # rubocop:disable Metrics/AbcSize
17
15
  # if args[:doctype] && !TYPES.include?(args[:doctype])
18
16
  # warn "[relaton-bsi] WARNING: invalid doctype: #{args[:doctype]}"
17
+ # warn "[relaton-bsi] Allowed doctypes are: #{TYPES.join(', ')}"
19
18
  # end
20
- @price_code = args.delete :price_code
21
- @cen_processing = args.delete :cen_processing
19
+ if args[:subdoctype] && !SUBDOCTYPES.include?(args[:subdoctype])
20
+ warn "[relaton-bsi] WARNING: invalid subdoctype: #{args[:subdoctype]}"
21
+ warn "[relaton-bsi] Allowed subdoctypes are: #{SUBDOCTYPES.join(', ')}"
22
+ end
22
23
  super
23
24
  end
24
25
 
@@ -28,7 +29,7 @@ module RelatonBsi
28
29
  # @option opts [String] :lang language
29
30
  # @return [String] XML
30
31
  def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
31
- super **opts do |b|
32
+ super(**opts) do |b|
32
33
  if opts[:bibdata] && (has_ext_attrs? || price_code ||
33
34
  !cen_processing.nil?)
34
35
  b.ext do
@@ -38,8 +39,6 @@ module RelatonBsi
38
39
  ics.each { |i| i.to_xml b }
39
40
  structuredidentifier&.to_xml b
40
41
  b.stagename stagename if stagename
41
- b.send "price-code", price_code if price_code
42
- b.send "cen-processing", cen_processing unless cen_processing.nil?
43
42
  end
44
43
  end
45
44
  end
@@ -49,7 +48,7 @@ module RelatonBsi
49
48
  # @return [RelatonBsi::BsiBibliographicItem]
50
49
  def self.from_hash(hash)
51
50
  item_hash = ::RelatonBsi::HashConverter.hash_to_bib(hash)
52
- new **item_hash
51
+ new(**item_hash)
53
52
  end
54
53
  end
55
54
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mechanize"
3
+ # require "mechanize"
4
4
  require "relaton_iso_bib"
5
5
  require "relaton_bsi/bsi_bibliographic_item"
6
6
  require "relaton_bsi/scrapper"
@@ -20,8 +20,8 @@ module RelatonBsi
20
20
  HitCollection.new code, year
21
21
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
22
22
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
23
- Net::ProtocolError
24
- raise RelatonBib::RequestError, "Could not access #{HitCollection::DOMAIN}"
23
+ Net::ProtocolError, Algolia::AlgoliaUnreachableHostError => e
24
+ raise RelatonBib::RequestError, e.message
25
25
  end
26
26
 
27
27
  # @param code [String] the BSI standard Code to look up
@@ -29,15 +29,9 @@ module RelatonBsi
29
29
  # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
30
30
  # @return [String] Relaton XML serialisation of reference
31
31
  def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
32
- # if year.nil?
33
- # /^(?<code1>[^\s]+\s[^\s]+)\s\((\d{2}\/)?(?<year1>\d+)\)$/ =~ code
34
- # unless code1.nil?
35
- # code = code1
36
- # year = year1
37
- # end
38
- # end
39
-
40
- ret = bib_get1(code, year, opts)
32
+ c, y = code.split ':'
33
+ year ||= y
34
+ ret = bib_get1(c, year, opts)
41
35
  return nil if ret.nil?
42
36
 
43
37
  # ret = ret.to_most_recent_reference unless year || opts[:keep_year]
@@ -67,14 +61,13 @@ module RelatonBsi
67
61
  end
68
62
 
69
63
  def search_filter(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
70
- %r{^BSI\s(?<code1>[^:]+)} =~ code
64
+ # %r{^BSI\s(?<code1>[^:]+)} =~ code
65
+ code1 = code.sub(/^BSI\s/, "")
71
66
  warn "[relaton-bsi] (\"#{code}\") fetching..."
72
67
  return [] unless code1
73
68
 
74
69
  result = search(code)
75
70
  result.select do |i|
76
- next true unless i.hit[:code]
77
-
78
71
  %r{^(?<code2>[^:]+)} =~ i.hit[:code]
79
72
  code2.include?(code1)
80
73
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "algolia"
3
4
  require "relaton_bsi/hit"
4
5
 
5
6
  module RelatonBsi
@@ -8,29 +9,39 @@ module RelatonBsi
8
9
  DOMAIN = "https://shop.bsigroup.com"
9
10
 
10
11
  # @return [Mechanize]
11
- attr_reader :agent
12
+ # attr_reader :agent
12
13
 
13
14
  # @param ref [String]
14
15
  # @param year [String]
15
16
  def initialize(ref, year = nil)
16
17
  super ref, year
17
- @agent = Mechanize.new
18
- resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
19
- @array = hits resp
18
+ # @agent = Mechanize.new
19
+ # resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
20
+ config = Algolia::Search::Config.new(application_id: "575YE157G9", api_key: "a057b4e74099445df2eddb7940828a10")
21
+ client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
22
+ index = client.init_index "shopify_products"
23
+ resp = index.search text # , facetFilters: "product_type:standard"
24
+ @array = hits resp[:hits]
20
25
  end
21
26
 
22
27
  private
23
28
 
24
- # @param resp [Mechanize::Page]
29
+ # @param hits [Array<Hash>]
25
30
  # @return [Array<RelatonBsi::Hit>]
26
- def hits(resp)
27
- resp.xpath("//div[@class='resultsInd']").map do |h|
28
- ref = h.at('div/h2/a')
29
- code = ref.text.strip
30
- url = ref[:href]
31
- d = h.at("//div/strong[.='Published Date:']/following-sibling::strong").text
32
- date = Date.parse(d)
33
- Hit.new({ code: code, url: url, date: date }, self)
31
+ def hits(hits) # rubocop:disable Metrics/MethodLength
32
+ hits.map do |h|
33
+ Hit.new(
34
+ {
35
+ code: h[:meta][:global][:primaryDesignator],
36
+ title: h[:title],
37
+ url: h[:handle],
38
+ date: h[:meta][:global][:publishedDate],
39
+ publisher: h[:meta][:global][:publisher],
40
+ status: h[:meta][:global][:status],
41
+ ics: h[:meta][:global][:icsCodesAlgoliaStringArray],
42
+ doctype: h[:product_type],
43
+ }, self
44
+ )
34
45
  end
35
46
  end
36
47
  end
@@ -5,7 +5,7 @@ module RelatonBsi
5
5
  def initialize
6
6
  @short = :relaton_bsi
7
7
  @prefix = "BSI"
8
- @defaultprefix = %r{^BSI\s}
8
+ @defaultprefix = %r{^(BSI|BS|PD)\s}
9
9
  @idtype = "BSI"
10
10
  end
11
11