Class: BookscanClient::Model::Book
- Inherits:
-
Object
- Object
- BookscanClient::Model::Book
- Defined in:
- lib/bookscan_client/model/book.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
Class Method Summary collapse
Instance Method Summary collapse
- #download_url ⇒ Object
-
#initialize(filename: nil, hash: nil, digest: nil, image_url: nil) ⇒ Book
constructor
A new instance of Book.
Constructor Details
#initialize(filename: nil, hash: nil, digest: nil, image_url: nil) ⇒ Book
Returns a new instance of Book.
6 7 8 9 10 11 |
# File 'lib/bookscan_client/model/book.rb', line 6 def initialize(filename: nil, hash: nil, digest: nil, image_url: nil) @filename = filename @hash = hash @digest = digest @image_url = image_url end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
4 5 6 |
# File 'lib/bookscan_client/model/book.rb', line 4 def digest @digest end |
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/bookscan_client/model/book.rb', line 4 def filename @filename end |
#hash ⇒ Object
Returns the value of attribute hash.
4 5 6 |
# File 'lib/bookscan_client/model/book.rb', line 4 def hash @hash end |
#image_url ⇒ Object
Returns the value of attribute image_url.
4 5 6 |
# File 'lib/bookscan_client/model/book.rb', line 4 def image_url @image_url end |
Class Method Details
.parse_books(page) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bookscan_client/model/book.rb', line 13 def self.parse_books(page) page.search("#sortable_box .showbook").map{|book_link| url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}" params = CGI.parse(URI.parse(url).query) next unless %w[f h d].all?{|key| params.keys.include?(key) } image = book_link.search("img") book = Book.new(filename: params["f"][0], hash: params["h"][0], digest: params["d"][0]) book.image_url = image[0].attr("data-original") unless image.empty? book } end |
Instance Method Details
#download_url ⇒ Object
27 28 29 |
# File 'lib/bookscan_client/model/book.rb', line 27 def download_url "#{BookscanClient::URL::DOWNLOAD}?d=#{digest}&f=#{CGI.escape(filename)}" end |