class Seinfeld::Application
Attributes
habits[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/seinfeld.rb, line 72 def initialize(*args) super *args @file = ENV['SEINFILE'] || File.join(ENV['HOME'], '.seinfile') if File.exists?(@file) data = JSON.parse(File.read(@file)) @habits = data.inject({}) { |_, a| _.merge(a[0] => Habit.new(a[1])) } else @habits = {} end end
Public Instance Methods
do(id)
click to toggle source
# File lib/seinfeld.rb, line 88 def do(id) @habits[id] ||= Habit.new(id: id) @habits[id].increment! save! puts "[#{id}] #{@habits[id].day_count} consecutive day(s)." end
list()
click to toggle source
# File lib/seinfeld.rb, line 96 def list @habits.each do |id, habit| puts "[#{id}] #{habit.day_count} consecutive day(s)." end end
save!()
click to toggle source
# File lib/seinfeld.rb, line 104 def save! File.open(@file, 'w') do |file| file.write(JSON.pretty_generate(habits.inject({}) {|_, a| _.merge(a[0] => a[1].as_json)} )) end end