Sha256: 354c2686130fb536ca40e4e53af0c7b5d0f8dd0182512943b9959944e981ac78

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module KindleManager
  class BooksParser < BaseParser
    class BookRow
      include KindleManager::Parsers::Common

      def initialize(node)
        @node = node
      end

      def inspect
        "#<#{self.class.name}:#{self.object_id} #{self.to_hash}>"
      end

      def asin
        @_asin ||= @node['name'].gsub(/\AcontentTabList_/, '')
      end

      def title
        @_title ||= @node.css("div[id^='title']").text
      end

      def tag
        @_tag ||= @node.css("div[id^='listViewTitleTag']").css('.myx-text-bold').first.text.strip
      end

      def author
        @_author ||= @node.css("div[id^='author']").text
      end

      def date
        @_date ||= parse_date(@node.css("div[id^='date']").text)
      end

      def collection_count
        @_collection_count ||= @node.css(".collectionsCount .myx-collection-count").first.text.strip.to_i
      end

      def to_hash
        hash = {}
        %w[asin title tag author date collection_count].each do |f|
          hash[f] = send(f)
        end
        hash
      end
    end

    def parse
      @_parsed ||= doc.css("div[id^='contentTabList_']").map{|e| BookRow.new(e) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kindle_manager-0.4.0 lib/kindle_manager/parsers/books_parser.rb
kindle_manager-0.3.0 lib/kindle_manager/parsers/books_parser.rb