Class: Klipbook::Book

Inherits:
Struct
  • Object
show all
Defined in:
lib/klipbook/sources/book.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#to_json, #to_map

Instance Attribute Details

#asinObject

Returns the value of attribute asin

Returns:

  • (Object)

    the current value of asin



3
4
5
# File 'lib/klipbook/sources/book.rb', line 3

def asin
  @asin
end

#authorObject

Returns the value of attribute author

Returns:

  • (Object)

    the current value of author



3
4
5
# File 'lib/klipbook/sources/book.rb', line 3

def author
  @author
end

#clippingsObject

Returns the value of attribute clippings

Returns:

  • (Object)

    the current value of clippings



3
4
5
# File 'lib/klipbook/sources/book.rb', line 3

def clippings
  @clippings
end

#last_updateObject

Returns the value of attribute last_update

Returns:

  • (Object)

    the current value of last_update



3
4
5
# File 'lib/klipbook/sources/book.rb', line 3

def last_update
  @last_update
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



3
4
5
# File 'lib/klipbook/sources/book.rb', line 3

def title
  @title
end

Class Method Details

.from_hash(hash) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/klipbook/sources/book.rb', line 33

def self.from_hash(hash)
  self.new.tap do |b|
    b.asin = hash['asin']
    b.author = hash['author']
    b.title = hash['title']
    b.last_update = hash['last_update']
    b.clippings = hash['clippings'].map { |clip| Klipbook::Clipping.from_hash(clip) }
  end
end

Instance Method Details

#get_bindingObject



13
14
15
# File 'lib/klipbook/sources/book.rb', line 13

def get_binding
  binding
end

#location_html(location) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/klipbook/sources/book.rb', line 17

def location_html(location)
  if asin
    "<a href=\"kindle://book?action=open&asin=#{asin}&location=#{location}\">loc #{location}</a>"
  else
    "loc #{location}"
  end
end

#location_markdown(location) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/klipbook/sources/book.rb', line 25

def location_markdown(location)
  if asin
    "[∞](kindle://book?action=open&asin=#{asin}&location=#{location})"
  else
    ""
  end
end

#sorted_clippingsObject



9
10
11
# File 'lib/klipbook/sources/book.rb', line 9

def sorted_clippings
  clippings.sort_by(&:location)
end

#title_and_authorObject



4
5
6
7
# File 'lib/klipbook/sources/book.rb', line 4

def title_and_author
  author_txt = author ? " by #{author}" : ''
  "#{title}#{author_txt}"
end