Class: Seinfeld::Application
- Inherits:
-
Thor
- Object
- Thor
- Seinfeld::Application
- Defined in:
- lib/seinfeld.rb
Instance Attribute Summary collapse
-
#habits ⇒ Object
readonly
Returns the value of attribute habits.
Instance Method Summary collapse
- #do(id) ⇒ Object
-
#initialize(*args) ⇒ Application
constructor
A new instance of Application.
- #list ⇒ Object
Constructor Details
#initialize(*args) ⇒ Application
Returns a new instance of Application.
72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |
Instance Attribute Details
#habits ⇒ Object (readonly)
Returns the value of attribute habits.
85 86 87 |
# File 'lib/seinfeld.rb', line 85 def habits @habits end |
Instance Method Details
#do(id) ⇒ Object
88 89 90 91 92 93 |
# 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 ⇒ Object
96 97 98 99 100 |
# File 'lib/seinfeld.rb', line 96 def list @habits.each do |id, habit| puts "[#{id}] #{habit.day_count} consecutive day(s)." end end |