Class: KindleNotebook::Highlight

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(highlight_attrs) ⇒ Highlight

Returns a new instance of Highlight.



7
8
9
10
11
12
13
14
# File 'lib/kindle_notebook/highlight.rb', line 7

def initialize(highlight_attrs)
  @text = highlight_attrs[:text]
  @page = highlight_attrs[:page]
  @context = highlight_attrs[:context]
  @book_asin = highlight_attrs[:book_asin]
  @raw_text = highlight_attrs[:raw_text]
  @raw_context = highlight_attrs[:raw_context]
end

Instance Attribute Details

#book_asinObject (readonly)

Returns the value of attribute book_asin.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def book_asin
  @book_asin
end

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def context
  @context
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def page
  @page
end

#raw_contextObject (readonly)

Returns the value of attribute raw_context.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def raw_context
  @raw_context
end

#raw_textObject (readonly)

Returns the value of attribute raw_text.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def raw_text
  @raw_text
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/kindle_notebook/highlight.rb', line 5

def text
  @text
end

Instance Method Details

#attributesObject



20
21
22
# File 'lib/kindle_notebook/highlight.rb', line 20

def attributes
  instance_variables.map { |v| v.to_s.gsub("@", "").to_sym }
end

#bookObject



16
17
18
# File 'lib/kindle_notebook/highlight.rb', line 16

def book
  @book ||= Client.books.find { |b| b.asin == book_asin }
end

#to_csvObject



24
25
26
# File 'lib/kindle_notebook/highlight.rb', line 24

def to_csv
  CSV::Row.new(attributes, attributes.map { |a| instance_variable_get("@#{a}") }).to_s
end