Class: DayOneKindle::Device
Constant Summary collapse
- CLIPPINGS_PATH =
'/documents/My Clippings.txt'.freeze
- VERSION_PATH =
'/system/version.txt'.freeze
- BACKUP_PATH =
'/clippings-backups'.freeze
- BACKUP_NAME =
'%Y%m%d-%H%M%S.txt'.freeze
Instance Attribute Summary collapse
-
#clippings_backups_path ⇒ Object
readonly
Returns the value of attribute clippings_backups_path.
-
#clippings_path ⇒ Object
readonly
Returns the value of attribute clippings_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #archive_highlights! ⇒ Object
- #clear_highlights! ⇒ Object
- #highlights ⇒ Object
-
#initialize(path, name) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(path, name) ⇒ Device
Returns a new instance of Device.
10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#clippings_backups_path ⇒ Object (readonly)
Returns the value of attribute clippings_backups_path.
8 9 10 |
# File 'lib/dayone-kindle/device.rb', line 8 def clippings_backups_path @clippings_backups_path end |
#clippings_path ⇒ Object (readonly)
Returns the value of attribute clippings_path.
8 9 10 |
# File 'lib/dayone-kindle/device.rb', line 8 def clippings_path @clippings_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/dayone-kindle/device.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/dayone-kindle/device.rb', line 8 def path @path end |
Class Method Details
.find_at(mount_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Method Details
#archive_highlights! ⇒ Object
21 22 23 24 25 26 27 |
# 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! ⇒ Object
29 30 31 |
# File 'lib/dayone-kindle/device.rb', line 29 def clear_highlights! File.truncate(clippings_path, 0) end |
#highlights ⇒ Object
17 18 19 |
# File 'lib/dayone-kindle/device.rb', line 17 def highlights ClippingsParser.new(raw_clippings).highlights end |