class DayOneKindle::Device

Constants

BACKUP_NAME
BACKUP_PATH
CLIPPINGS_PATH
VERSION_PATH

Attributes

clippings_backups_path[R]
clippings_path[R]
name[R]
path[R]

Public Class Methods

find_at(mount_path) click to toggle source
# File lib/dayone-kindle/device.rb, line 33
def self.find_at(mount_path)
  volumes = Dir.entries(mount_path) - ['.', '..']

  volumes.map do |name|
    path = File.join(mount_path, name)
    version_path = File.join(path, VERSION_PATH)

    if File.exist?(version_path) && IO.read(version_path) =~ /^Kindle/
      new(path, name)
    end
  end.compact
end
new(path, name) click to toggle source
# File lib/dayone-kindle/device.rb, line 10
def initialize(path, name)
  @path = path
  @name = name
  @clippings_path = File.join(path, CLIPPINGS_PATH)
  @clippings_backups_path = File.join(path, BACKUP_PATH)
end

Public Instance Methods

archive_highlights!() click to toggle source
# File lib/dayone-kindle/device.rb, line 21
def archive_highlights!
  Dir.mkdir(clippings_backups_path) unless Dir.exist?(clippings_backups_path)
  backup_name = Time.now.strftime(BACKUP_NAME)
  backup_file_path = File.join(clippings_backups_path, backup_name)
  FileUtils.cp(clippings_path, backup_file_path)
  backup_file_path
end
clear_highlights!() click to toggle source
# File lib/dayone-kindle/device.rb, line 29
def clear_highlights!
  File.truncate(clippings_path, 0)
end
highlights() click to toggle source
# File lib/dayone-kindle/device.rb, line 17
def highlights
  ClippingsParser.new(raw_clippings).highlights
end

Private Instance Methods

raw_clippings() click to toggle source
# File lib/dayone-kindle/device.rb, line 48
def raw_clippings
  File.read(clippings_path).gsub("\r", '')
end