alexandrite 0.1.1.pre.alpha → 0.1.2.pre.alpha

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: b04594e2817421efbc7843faddd9ea5b6bee3ff093d52c4328d3fa1b76680905
4
- data.tar.gz: 6ec96b26a30b7609dcdf2da25ce6ccaf38279d3fb232da07327e6699b39661ff
3
+ metadata.gz: 1904340a4469d9f82f1d42d16a58cdd7a63e0a23711ed040d20c63648164d4fc
4
+ data.tar.gz: a6e306d3416403661661ed1bee823d43bd332f446cb1e1ee61e1529c8f5362aa
5
5
  SHA512:
6
- metadata.gz: b028aba504cc9e5f14deac610c81eb1c18066b90a563f0d9486cd6f06ca4b3a1be803333417fd0c06240be1db021842d334088695d512d06ea873dbd4f126b08
7
- data.tar.gz: 66563405941ad6bd600b26466d229eb93929de988848547305322e878d3642df4da7cba555eafa3f22c055ea5c07314a85bc5028c70d352c5479a535324d8e06
6
+ metadata.gz: 40f3d5f4f06ce58a3f99156f4a26e399cb8b3e1c852a34de923947aa1b5cad75f39a2d75cc39ed86fa2a765292318ec890e5acc201fa922d861b91618e4d1d96
7
+ data.tar.gz: 0fc0a88be83ab17e5753cd389dac7de71ecffaa6915e59d7047a5dd4dc547b84a7fb0a2231be8e22fd911cf162945ad2fa16dafa531af82b0891f6539e22d3eb
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alexandrite
4
- VERSION = '0.1.1-alpha'
4
+ VERSION = '0.1.2-alpha'
5
5
  end
@@ -45,12 +45,14 @@ module Alexandrite
45
45
  data[:isbn13] = volume_info['ISBN_13']
46
46
  return data
47
47
  end
48
-
49
- volume_info['industryIdentifiers'].each do |identifier|
50
- data[:isbn10] = identifier['identifier'] if identifier['type'] == 'ISBN_10'
51
- data[:isbn13] = identifier['identifier'] if identifier['type'] == 'ISBN_13'
48
+ begin
49
+ volume_info['industryIdentifiers'].each do |identifier|
50
+ data[:isbn10] = identifier['identifier'] if identifier['type'] == 'ISBN_10'
51
+ data[:isbn13] = identifier['identifier'] if identifier['type'] == 'ISBN_13'
52
+ end
53
+ rescue NoMethodError
54
+ data
52
55
  end
53
-
54
56
  data
55
57
  end
56
58
  end
@@ -31,28 +31,37 @@ module Alexandrite
31
31
  Nokogiri::XML(conn.get(search).body)
32
32
  end
33
33
 
34
+ def extract_value(attribute)
35
+ return nil unless attribute.respond_to?(:value)
36
+
37
+ attribute.value
38
+ end
39
+
40
+ def extract_nokogiri_data(document, children, attribute)
41
+ extract_value(document.css(children).attribute(attribute))
42
+ end
43
+
34
44
  def get_book_data(result)
35
45
  isbn = result.css('input').children.text
36
46
  isbn_type = define_isbn_type(isbn)
37
47
  {
38
48
  'origin' => 'OCLC API',
39
- 'title' => result.css('work').attribute('title').value,
40
- 'authors' => result.css('work').attribute('author').value,
41
- 'ddc' => result.css('mostPopular').attribute('nsfa').value,
49
+ 'title' => extract_nokogiri_data(result, 'work', 'title'),
50
+ 'authors' => extract_nokogiri_data(result, 'work', 'author'),
51
+ 'ddc' => extract_nokogiri_data(result, 'mostPopular', 'nsfa'),
42
52
  isbn_type => isbn
43
53
  }
44
54
  end
45
55
 
46
56
  def recommend_classification(key, query, length = 5, mode: 'ddc')
47
57
  results = search_by(key, query)
48
-
49
58
  response_cases(results, length, mode)
50
59
  end
51
60
 
52
61
  private
53
62
 
54
63
  # @return [Integer]
55
- def get_response_code(result) = result.css('response').attribute('code').value.to_i
64
+ def get_response_code(result) = extract_nokogiri_data(result, 'response', 'code').to_i
56
65
 
57
66
  def get_owis(result, length)
58
67
  owis = []
@@ -87,15 +96,8 @@ module Alexandrite
87
96
  Alexandrite::BookData.create_data(get_book_data(query.result))
88
97
  end
89
98
 
90
- def retry_create_new_book(query)
91
- owi = get_owis(query.result, 1)[0]
92
- new_query = Alexandrite::OCLC.new('owi', owi)
93
- volume_info = get_book_data(new_query.result)
94
- Alexandrite::BookData.create_data(volume_info)
95
- end
96
-
97
- def handle_error_creating_book(query)
98
- raise ErrorType::DataNotFound, response_cases(query.result, 0, 'none')
99
+ def handle_error_creating_book
100
+ raise ErrorType::DataNotFound, yield
99
101
  rescue StandardError => e
100
102
  Alexandrite::BookData.create_data({ :error_message => e.message, 'origin' => 'OCLC API' })
101
103
  end
@@ -129,9 +131,9 @@ module Alexandrite
129
131
  when 0, 2
130
132
  create_new_book(query)
131
133
  when 4
132
- retry_create_new_book(query)
134
+ handle_error_creating_book { 'Not found exact item. Check coincidences' }
133
135
  else
134
- handle_error_creating_book(query)
136
+ handle_error_creating_book { response_cases(query.result, 0, 'none') }
135
137
  end
136
138
  end
137
139
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexandrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre.alpha
4
+ version: 0.1.2.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. P. Pérez-Tejada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-22 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: 1.3.1
191
191
  requirements: []
192
- rubygems_version: 3.3.7
192
+ rubygems_version: 3.4.5
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Tools for fetching books data from Google and OCLC