Class: KindleHighlights::Highlight

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle_highlights/highlight.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asin:, text:, location:) ⇒ Highlight

Returns a new instance of Highlight.


13
14
15
16
17
# File 'lib/kindle_highlights/highlight.rb', line 13

def initialize(asin:, text:, location:)
  @asin = asin
  @text = text
  @location = location
end

Instance Attribute Details

#asinObject

Returns the value of attribute asin


3
4
5
# File 'lib/kindle_highlights/highlight.rb', line 3

def asin
  @asin
end

#locationObject

Returns the value of attribute location


3
4
5
# File 'lib/kindle_highlights/highlight.rb', line 3

def location
  @location
end

#textObject

Returns the value of attribute text


3
4
5
# File 'lib/kindle_highlights/highlight.rb', line 3

def text
  @text
end

Class Method Details

.from_html_elements(book:, html_elements:) ⇒ Object


5
6
7
8
9
10
11
# File 'lib/kindle_highlights/highlight.rb', line 5

def self.from_html_elements(book:, html_elements:)
  new(
    asin: book.asin,
    text: html_elements.children.search("div.kp-notebook-highlight").first.text.squish,
    location: html_elements.children.search("input#kp-annotation-location").first.attributes["value"].value,
  )
end

Instance Method Details

#to_sObject


19
20
21
# File 'lib/kindle_highlights/highlight.rb', line 19

def to_s
  text
end