Class: AmazonBook::Link
- Inherits:
-
Object
- Object
- AmazonBook::Link
- Defined in:
- lib/amazon_book/link.rb
Constant Summary collapse
- BOOK_PATHS =
[ %r{/dp/(\d{9}[\dX])}, %r{/gp/offer-listing/(\d{9}[\dX])}, %r{/gp/product/(\d{9}[\dX])}, %r{/exec/obidos/ASIN/(\d{9}[\dX])}, %r{/o/ASIN/(\d{9}[\dX])} ].freeze
- AMAZON_DOMAINS =
[ 'amazon.ca', 'amazon.cn', 'amazon.co.jp', 'amazon.co.uk', 'amazon.com', 'amazon.com.au', 'amazon.com.br', 'amazon.com.mx', 'amazon.de', 'amazon.es', 'amazon.fr', 'amazon.in', 'amazon.it', 'amazon.nl' ].freeze
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #book? ⇒ Boolean
-
#initialize(url) ⇒ Link
constructor
A new instance of Link.
- #isbn13 ⇒ Object
Constructor Details
#initialize(url) ⇒ Link
Returns a new instance of Link.
30 31 32 |
# File 'lib/amazon_book/link.rb', line 30 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
28 29 30 |
# File 'lib/amazon_book/link.rb', line 28 def url @url end |
Instance Method Details
#book? ⇒ Boolean
34 35 36 |
# File 'lib/amazon_book/link.rb', line 34 def book? correct_domain? && isbn13 end |
#isbn13 ⇒ Object
38 39 40 41 42 |
# File 'lib/amazon_book/link.rb', line 38 def isbn13 BOOK_PATHS.flat_map do |path_regex| Identifiers::ISBN.extract(url[path_regex, 1]) end.first end |