class Seinfeld::Habit

Attributes

attributes[R]
entries[R]

Public Class Methods

new(attributes={}) click to toggle source
# 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

Public Instance Methods

as_json(options={}) click to toggle source
# File lib/seinfeld.rb, line 40
def as_json(options={})
  attributes.merge(
    'entries' => entries.map(&:as_json)
  )
end
day_count() click to toggle source
# File lib/seinfeld.rb, line 56
def day_count
  @entries.length
end
has_entry_for_date?(date) click to toggle source
# File lib/seinfeld.rb, line 46
def has_entry_for_date?(date)
  @entries.any? {|e| e.date.to_s == date.to_s }
end
increment!() click to toggle source
# File lib/seinfeld.rb, line 50
def increment!
  unless has_entry_for_date?(Date.today)
    @entries << Entry.new
  end
end
method_missing(name, *args) click to toggle source
Calls superclass method
# 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