Class: KindleFortune

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle_fortune.rb,
lib/kindle_fortune/version.rb

Constant Summary collapse

USERNAME =
`whoami`.strip
DEFAULT_UPDATED_DATAFILE =
'/Volumes/Kindle/documents/My Clippings.txt'.freeze
DEFAULT_CURRENT_DATAFILE =
"/Users/#{USERNAME}/.config/kindle_fortune.json".freeze
VERSION =
'0.0.1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(updated_datafile:, current_datafile:) ⇒ KindleFortune

Returns a new instance of KindleFortune.



11
12
13
14
# File 'lib/kindle_fortune.rb', line 11

def initialize(updated_datafile:, current_datafile:)
  @current_datafile = current_datafile || DEFAULT_CURRENT_DATAFILE
  @updated_datafile = updated_datafile || DEFAULT_UPDATED_DATAFILE
end

Instance Method Details



16
17
18
19
20
21
22
23
24
# File 'lib/kindle_fortune.rb', line 16

def fetch_cookie
  if File.exist?(@updated_datafile) then prepare_extracts
  else import_extracts
  end

  raise 'No Kindle highlights detected' unless File.exist?(@current_datafile)
  fortune_cookie = @extracts[rand(@extracts.count)]
  pretty_print(fortune_cookie)
end