Class: BookscanClient::Model::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/bookscan_client/model/book.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#digestObject

Returns the value of attribute digest.



4
5
6
# File 'lib/bookscan_client/model/book.rb', line 4

def digest
  @digest
end

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/bookscan_client/model/book.rb', line 4

def filename
  @filename
end

#hashObject

Returns the value of attribute hash.



4
5
6
# File 'lib/bookscan_client/model/book.rb', line 4

def hash
  @hash
end

#image_urlObject

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_urlObject



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