class Klipbook::Sources::KindleDevice::File
Public Class Methods
new(infile, max_books, file_parser=FileParser.new)
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 5 def initialize(infile, max_books, file_parser=FileParser.new) @file_text = infile.strip @file_parser = file_parser @max_books = max_books end
Public Instance Methods
books()
click to toggle source
TODO Shift max books here
# File lib/klipbook/sources/kindle_device/file.rb, line 12 def books @books ||= build_books.take(@max_books) end
Private Instance Methods
book_from_entries(entries)
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 40 def book_from_entries(entries) entries.sort! { |ea, eb| ea.location <=> eb.location } Klipbook::Book.new.tap do |b| b.title = entries.first.title b.author = entries.first.author b.last_update = entries.map(&:added_on).max b.clippings = entries.map do |e| Klipbook::Clipping.new.tap do |c| c.location = e.location c.page = e.page c.text = e.text c.type = e.type end end end end
books_from_entries(entries)
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 34 def books_from_entries(entries) entries.select { |entry| entry.type != :bookmark } .group_by(&:title) .map { |title, book_entries| book_from_entries(book_entries) } end
build_books()
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 18 def build_books sorted_entries = extract_sorted_entries_from_file_text build_sorted_book_list(sorted_entries) end
build_sorted_book_list(sorted_entries)
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 28 def build_sorted_book_list(sorted_entries) books_from_entries(sorted_entries).sort do |book_a, book_b| book_b.last_update <=> book_a.last_update end end
extract_sorted_entries_from_file_text()
click to toggle source
# File lib/klipbook/sources/kindle_device/file.rb, line 23 def extract_sorted_entries_from_file_text entries = @file_parser.extract_entries(@file_text) entries.sort { |entry_a, entry_b| entry_a.title <=> entry_b.title } end