Sha256: b34771c9958ffd7851a7a9d5f20c5609803b2ec3263197b1eb839938892fdbf5

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

class Libri::Book
    attr_accessor :title_by_author, :about_author, :availability, :blurbs_and_plot, :url, :excerpt, :related_books, :book

    def self.scrape_book(book)
        html = book[:url]
        book_page = Nokogiri::HTML(open(html))
        info_section = book_page.css("div.tabpanel")

        related_books_hash = {}

        book_info_hash = {
            :title_by_author => info_section.css("div#productInfoOverview div.mb-m").text,
            :blurbs_and_plot => info_section.css("div#productInfoOverview p").map(&:text).join("\n").strip,
            :about_author => info_section.css("div#MeetTheAuthor div.text--medium").text.strip,
            :excerpt => info_section.xpath("//div[@class='read-an-excerpt']/p[not(@class) and position()<7]").map(&:text).join("\n"),
            # :related_books => book_page.css("div.product-shelf-info").each { |book|
            #     related_books_hash = {
            #         :title => book.css("div.product-shelf-title").text.strip,
            #         :author => book.css("div.product-shelf-author").text.strip,
            #         :url => "https://www.barnesandnoble.com" + book.css("a").attribute("href").value
            #     }
            # },
            :availability => book_page.css("button#pdp-marketplace-btn").text.strip,
            :url => book[:url]
        }

        book_info_hash.delete_if { |key, val| val.to_s.strip.empty? }

    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
libri-0.1.1 lib/libri/book.rb
libri-0.1.0 lib/libri/book.rb