class DayOneKindle::DayOne::Entry
Attributes
content[RW]
created_at[RW]
Public Class Methods
new(content, options = {})
click to toggle source
# File lib/dayone-kindle/day_one.rb, line 18 def initialize(content, options = {}) @content = content @tags = options[:tags] || [] @created_at = options[:created_at] || Time.now end
Public Instance Methods
file()
click to toggle source
# File lib/dayone-kindle/day_one.rb, line 28 def file @file ||= File.join(DayOne::journal_location, 'entries', "#{uuid}.doentry") end
save!()
click to toggle source
# File lib/dayone-kindle/day_one.rb, line 61 def save! File.open(file, 'w') { |f| f.write(to_xml) } uuid end
to_xml()
click to toggle source
# File lib/dayone-kindle/day_one.rb, line 32 def to_xml tags_xml = '' unless tags.empty? tags_xml = <<XML <key>Tags</key> <array> #{tags.map { |tag| " <string>#{tag}</string>" }.join("\n ") } </array> XML end <<-XML <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Creation Date</key> <date>#{created_at.utc.iso8601}</date> <key>Entry Text</key> <string>#{content}</string> #{tags_xml.strip} <key>UUID</key> <string>#{uuid}</string> </dict> </plist> XML end
uuid()
click to toggle source
# File lib/dayone-kindle/day_one.rb, line 24 def uuid @uuid ||= `uuidgen`.gsub('-', '').strip end