Class: KindleManager::BooksParser::BookRow

Inherits:
Object
  • Object
show all
Includes:
Parsers::Common
Defined in:
lib/kindle_manager/parsers/books_parser.rb

Instance Method Summary collapse

Methods included from Parsers::Common

#parse_date

Constructor Details

#initialize(node, options = {}) ⇒ BookRow

Returns a new instance of BookRow.



7
8
9
10
# File 'lib/kindle_manager/parsers/books_parser.rb', line 7

def initialize(node, options = {})
  @node = node
  @fetched_at = options[:fetched_at]
end

Instance Method Details

#asinObject



16
17
18
# File 'lib/kindle_manager/parsers/books_parser.rb', line 16

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

#authorObject



28
29
30
# File 'lib/kindle_manager/parsers/books_parser.rb', line 28

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

#collection_countObject



36
37
38
# File 'lib/kindle_manager/parsers/books_parser.rb', line 36

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

#dateObject



32
33
34
# File 'lib/kindle_manager/parsers/books_parser.rb', line 32

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

#inspectObject



12
13
14
# File 'lib/kindle_manager/parsers/books_parser.rb', line 12

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

#tagObject



24
25
26
# File 'lib/kindle_manager/parsers/books_parser.rb', line 24

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

#titleObject



20
21
22
# File 'lib/kindle_manager/parsers/books_parser.rb', line 20

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

#to_hashObject



40
41
42
43
44
45
46
# File 'lib/kindle_manager/parsers/books_parser.rb', line 40

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