class KindleManager::HighlightsParser::BookWithNote
Public Class Methods
new(node, options = {})
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 6 def initialize(node, options = {}) @node = node @fetched_at = options[:fetched_at] end
Public Instance Methods
asin()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 15 def asin @_asin ||= @node.css('#kp-notebook-annotations-asin').first['value'] end
count_summary()
click to toggle source
This can be used to verify the count of hightlights and notes
# File lib/kindle_manager/parsers/highlights_parser.rb, line 67 def count_summary @_count_summary ||= begin text = @node.css('.kp-notebook-row-separator > .kp-notebook-metadata').last.text.strip a, b = text.split('|').map{|text| m = text.match(/\d+/); m.nil? ? nil : m[0].to_i } {'text' => text, 'highlights_count' => a, 'notes_count' => b} end end
highlights()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 58 def highlights highlights_and_notes.reject{|e| e['highlight'].blank? } end
highlights_and_notes()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 39 def highlights_and_notes @_highlights_and_notes ||= begin # Excluding the first element which has book info @node.css('.a-spacing-base')[1..-1].map do |node| begin location = node.css('#kp-annotation-location').first['value'].to_i highlight_node = node.css('.kp-notebook-highlight').first highlight = highlight_node && highlight_node.css('#highlight').first.text color = highlight_node && highlight_node['class'].split.find{|v| v =~ /kp-notebook-highlight-/ }.split('-').last note = node.css('#note').first.text {'location' => location, 'highlight' => highlight, 'color' => color, 'note' => note} rescue => e puts "[DEBUG] #{e.class}: #{e.message}\n#{node.to_html}\n" next end end.compact end end
highlights_count()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 31 def highlights_count @_highlights_count ||= @node.css('.kp-notebook-highlight').size end
inspect()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 11 def inspect "#<#{self.class.name}:#{self.object_id} #{self.to_hash}>" end
invalid?()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 83 def invalid? !!(asin.blank? || count_summary['text'] =~ /--/) end
last_annotated_on()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 27 def last_annotated_on @_last_annotated_on ||= parse_date(@node.css('#kp-notebook-annotated-date').text) end
notes()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 62 def notes highlights_and_notes.reject{|e| e['note'].blank? } end
notes_count()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 35 def notes_count @_notes_count ||= @node.css('.kp-notebook-note').reject{|e| e['class'] =~ /aok-hidden/ }.size end
title()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 19 def title @_title ||= @node.css('h3.kp-notebook-metadata').text end
to_hash()
click to toggle source
# File lib/kindle_manager/parsers/highlights_parser.rb, line 75 def to_hash hash = {} %w[asin title author last_annotated_on highlights_count notes_count highlights_and_notes].each do |f| hash[f] = send(f) end hash end