Class: Seinfeld::Habit
- Inherits:
-
Object
- Object
- Seinfeld::Habit
- Defined in:
- lib/seinfeld.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #day_count ⇒ Object
- #has_entry_for_date?(date) ⇒ Boolean
- #increment! ⇒ Object
-
#initialize(attributes = {}) ⇒ Habit
constructor
A new instance of Habit.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Habit
Returns a new instance of Habit.
29 30 31 32 33 34 35 36 |
# File 'lib/seinfeld.rb', line 29 def initialize(attributes={}) @attributes = attributes if @attributes['entries'] @entries = @attributes['entries'].map {|attrs| Entry.new(attrs)} else @entries = [] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/seinfeld.rb', line 60 def method_missing(name, *args) if attributes[name.to_s] return attributes[name.to_s] else super end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
38 39 40 |
# File 'lib/seinfeld.rb', line 38 def attributes @attributes end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
38 39 40 |
# File 'lib/seinfeld.rb', line 38 def entries @entries end |
Instance Method Details
#as_json(options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/seinfeld.rb', line 40 def as_json(={}) attributes.merge( 'entries' => entries.map(&:as_json) ) end |
#day_count ⇒ Object
56 57 58 |
# File 'lib/seinfeld.rb', line 56 def day_count @entries.length end |
#has_entry_for_date?(date) ⇒ Boolean
46 47 48 |
# File 'lib/seinfeld.rb', line 46 def has_entry_for_date?(date) @entries.any? {|e| e.date.to_s == date.to_s } end |