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



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

def asin
  @_asin ||= title_node.attributes['id'].value.remove('content-title-')
end

#authorObject



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

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

#collection_countObject



41
42
43
# File 'lib/kindle_manager/parsers/books_parser.rb', line 41

def collection_count
  @_collection_count ||= @node.css('.dropdown_count').first&.text&.strip.to_i
end

#dateObject



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

def date
  @_date ||= parse_date(@node.css("div[id^='content-acquired-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



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

def tag
  @_tag ||= @node.css('.information_row.tags').first&.text&.strip
end

#titleObject



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

def title
  @_title ||= title_node.text
end

#title_nodeObject



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

def title_node
  # Possible to use "div[id^='content-title-']"
  @_title_node ||= @node.css('.digital_entity_title').first
end

#to_hashObject



45
46
47
48
49
50
51
# File 'lib/kindle_manager/parsers/books_parser.rb', line 45

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