Sha256: cb2c7af7dcfd4ab8967e8e9f965c877c66850455408341b41024ea85e8ddb1bb
Contents?: true
Size: 981 Bytes
Versions: 1
Compression:
Stored size: 981 Bytes
Contents
class BookscanClient module Model class Book attr_accessor :filename, :hash, :digest, :image_url def initialize(filename: nil, hash: nil, digest: nil, image_url: nil) @filename = filename @hash = hash @digest = digest @image_url = image_url end 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 def download_url "#{BookscanClient::URL::DOWNLOAD}?d=#{digest}&f=#{CGI.escape(filename)}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bookscan_client-0.0.1 | lib/bookscan_client/model/book.rb |