Class: KindleHighlights::Book
- Inherits:
-
Object
- Object
- KindleHighlights::Book
- Defined in:
- lib/kindle_highlights/book.rb
Instance Attribute Summary collapse
-
#asin ⇒ Object
Returns the value of attribute asin.
-
#author ⇒ Object
Returns the value of attribute author.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #highlights_from_amazon ⇒ Object
-
#initialize(asin:, author:, title:, mechanize_agent: nil) ⇒ Book
constructor
A new instance of Book.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(asin:, author:, title:, mechanize_agent: nil) ⇒ Book
Returns a new instance of Book.
14 15 16 17 18 19 |
# File 'lib/kindle_highlights/book.rb', line 14 def initialize(asin:, author:, title:, mechanize_agent: nil) @asin = asin @author = @title = title @mechanize_agent = mechanize_agent end |
Instance Attribute Details
#asin ⇒ Object
Returns the value of attribute asin.
3 4 5 |
# File 'lib/kindle_highlights/book.rb', line 3 def asin @asin end |
#author ⇒ Object
Returns the value of attribute author.
3 4 5 |
# File 'lib/kindle_highlights/book.rb', line 3 def @author end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/kindle_highlights/book.rb', line 3 def title @title end |
Class Method Details
.from_html_elements(html_element:, mechanize_agent:) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/kindle_highlights/book.rb', line 5 def self.from_html_elements(html_element:, mechanize_agent:) new( mechanize_agent: mechanize_agent, asin: html_element.attributes["id"].value.squish, title: html_element.children.search("h2").first.text.squish, author: html_element.children.search("p").first.text.split(":").last.strip.squish ) end |
Instance Method Details
#highlights_from_amazon ⇒ Object
29 30 31 32 33 |
# File 'lib/kindle_highlights/book.rb', line 29 def highlights_from_amazon return [] unless mechanize_agent.present? @highlights ||= fetch_highlights_from_amazon end |
#inspect ⇒ Object
25 26 27 |
# File 'lib/kindle_highlights/book.rb', line 25 def inspect "<#{self.class}: #{inspectable_vars}>" end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/kindle_highlights/book.rb', line 21 def to_s "#{title} by #{}" end |