Class: Diary::Entry
- Inherits:
-
Object
- Object
- Diary::Entry
- Defined in:
- lib/diary-ruby/entry.rb
Constant Summary collapse
- CURRENT_VERSION =
1
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#key ⇒ Object
Returns the value of attribute key.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#text ⇒ Object
Returns the value of attribute text.
-
#time ⇒ Object
Returns the value of attribute time.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #formatted_text ⇒ Object
-
#initialize(version, options = {}) ⇒ Entry
constructor
A new instance of Entry.
- #to_hash ⇒ Object
Constructor Details
#initialize(version, options = {}) ⇒ Entry
Returns a new instance of Entry.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diary-ruby/entry.rb', line 52 def initialize(version, ={}) @version = version || CURRENT_VERSION @day = [:day] @time = [:time] @tags = [:tags] || [] @text = [:text] @title = [:title] if [:key].nil? @key = Entry.keygen(day, time) else @key = [:key] end end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def day @day end |
#key ⇒ Object
Returns the value of attribute key.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def key @key end |
#tags ⇒ Object
Returns the value of attribute tags.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def @tags end |
#text ⇒ Object
Returns the value of attribute text.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def text @text end |
#time ⇒ Object
Returns the value of attribute time.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def time @time end |
#title ⇒ Object
Returns the value of attribute title.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
17 18 19 |
# File 'lib/diary-ruby/entry.rb', line 17 def version @version end |
Class Method Details
.from_store(record) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/diary-ruby/entry.rb', line 21 def self.from_store(record) if record[:version] == 1 self.new( record[:version], day: record[:day], time: record[:time], tags: record[:tags], text: record[:text], title: record[:title], key: record[:key], ) end end |
.generate(options = {}, store) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/diary-ruby/entry.rb', line 39 def self.generate(={}, store) [:last_update_at] = store.read(:last_update_at) # convert Arrays to dumb CSV .each do |(k, v)| if v.is_a?(Array) [k] = v.join(', ') end end TEMPLATE % end |
.keygen(day, time) ⇒ Object
35 36 37 |
# File 'lib/diary-ruby/entry.rb', line 35 def self.keygen(day, time) "%s-%s" % [day, time] end |
Instance Method Details
#formatted_text ⇒ Object
68 69 70 |
# File 'lib/diary-ruby/entry.rb', line 68 def formatted_text RDiscount.new(text).to_html end |
#to_hash ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/diary-ruby/entry.rb', line 72 def to_hash { version: version, day: day, time: time, tags: , text: text, title: '', key: key, } end |