Class: DayOneKindle::DayOne::Entry
- Defined in:
- lib/dayone-kindle/day_one.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(content, options = {}) ⇒ Entry
constructor
A new instance of Entry.
- #save! ⇒ Object
- #to_xml ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(content, options = {}) ⇒ Entry
Returns a new instance of Entry.
18 19 20 21 22 |
# File 'lib/dayone-kindle/day_one.rb', line 18 def initialize(content, = {}) @content = content @tags = [:tags] || [] @created_at = [:created_at] || Time.now end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
16 17 18 |
# File 'lib/dayone-kindle/day_one.rb', line 16 def content @content end |
#created_at ⇒ Object
Returns the value of attribute created_at.
16 17 18 |
# File 'lib/dayone-kindle/day_one.rb', line 16 def created_at @created_at end |
#tags ⇒ Object
Returns the value of attribute tags.
16 17 18 |
# File 'lib/dayone-kindle/day_one.rb', line 16 def @tags end |
Instance Method Details
#file ⇒ Object
28 29 30 |
# File 'lib/dayone-kindle/day_one.rb', line 28 def file @file ||= File.join(DayOne::journal_location, 'entries', "#{uuid}.doentry") end |
#save! ⇒ Object
61 62 63 64 |
# File 'lib/dayone-kindle/day_one.rb', line 61 def save! File.open(file, 'w') { |f| f.write(to_xml) } uuid end |
#to_xml ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dayone-kindle/day_one.rb', line 32 def to_xml = '' unless .empty? = <<XML <key>Tags</key> <array> #{.map { |tag| " <string>#{tag}</string>" }.join("\n ") } </array> XML end <<-XML <?xml version="1.0" encoding="UTF-8"?> <!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> #{.strip} <key>UUID</key> <string>#{uuid}</string> </dict> </plist> XML end |
#uuid ⇒ Object
24 25 26 |
# File 'lib/dayone-kindle/day_one.rb', line 24 def uuid @uuid ||= `uuidgen`.gsub('-', '').strip end |