relaton-bsi 1.8.3 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -11
- data/.rubocop.yml +1 -1
- data/README.adoc +12 -3
- data/grammars/biblio.rng +1 -0
- data/grammars/bsi.rng +30 -18
- data/grammars/isodoc.rng +246 -10
- data/grammars/isostandard.rng +19 -3
- data/grammars/reqt.rng +31 -2
- data/lib/relaton_bsi/bsi_bibliographic_item.rb +13 -14
- data/lib/relaton_bsi/bsi_bibliography.rb +3 -5
- data/lib/relaton_bsi/hit_collection.rb +24 -13
- data/lib/relaton_bsi/schema.json +24882 -0
- data/lib/relaton_bsi/scrapper.rb +136 -78
- data/lib/relaton_bsi/version.rb +1 -1
- data/lib/relaton_bsi/xml_parser.rb +1 -3
- data/relaton_bsi.gemspec +5 -11
- metadata +23 -8
@@ -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,
|
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
|
@@ -68,8 +68,6 @@ module RelatonBsi
|
|
68
68
|
|
69
69
|
result = search(code)
|
70
70
|
result.select do |i|
|
71
|
-
next true unless i.hit[:code]
|
72
|
-
|
73
71
|
%r{^(?<code2>[^:]+)} =~ i.hit[:code]
|
74
72
|
code2.include?(code1)
|
75
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
|
-
|
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
|
29
|
+
# @param hits [Array<Hash>]
|
25
30
|
# @return [Array<RelatonBsi::Hit>]
|
26
|
-
def hits(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|