class KindleFortune
Constants
- DEFAULT_CURRENT_DATAFILE
- DEFAULT_UPDATED_DATAFILE
- USERNAME
- VERSION
Public Class Methods
new(updated_datafile:, current_datafile:)
click to toggle source
# 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
Public Instance Methods
Private Instance Methods
import_extracts()
click to toggle source
# File lib/kindle_fortune.rb, line 28 def import_extracts @extracts = JSON.parse(File.read(@current_datafile)) end
prepare_extracts()
click to toggle source
# File lib/kindle_fortune.rb, line 32 def prepare_extracts @extracts = KindleClippings::Parser .new .parse_file(@updated_datafile) .select { |clipping| clipping.type== :Highlight } .map do |clipping| { 'book' => clipping.book_title, 'author' => clipping.author, 'location' => clipping.location, 'content' => clipping.content } end store_extracts end
pretty_print(cookie)
click to toggle source
# File lib/kindle_fortune.rb, line 49 def pretty_print(cookie) "#{cookie['book']} (#{cookie['author']}) [L#{cookie['location']}] "\ "\n\n #{cookie['content']}" end
store_extracts()
click to toggle source
# File lib/kindle_fortune.rb, line 54 def store_extracts File.delete(@current_datafile) if File.exist?(@current_datafile) File.open(@current_datafile, 'a') { |file| file.write(JSON.pretty_generate(@extracts)) } end