class Timesheets::Commands::Status
Public Instance Methods
run()
click to toggle source
# File lib/timesheets/commands/status.rb, line 4 def run strings = [] if session_in_progress? strings << "Current work session has been active for #{active_time}." else strings << "Not currently working." end strings << "Total time today is #{total_time_today}." logger.log strings.join(' ') end
Private Instance Methods
active_time(the_entries = [entries.last])
click to toggle source
# File lib/timesheets/commands/status.rb, line 17 def active_time(the_entries = [entries.last]) hoursf = the_entries.map {|entry| hours_in_entry(entry) }.reduce(:+) return "0 minutes" unless hoursf hours = hoursf.to_i mins = ((hoursf - hours) * 60).to_i [pluralize('hour', hours), pluralize('minute', mins)] .reject {|string| string == "0 hours" } .join(', ') end
pluralize(word, n)
click to toggle source
# File lib/timesheets/commands/status.rb, line 32 def pluralize(word, n) n == 1 && "#{n} #{word}" || "#{n} #{word}s" end
total_time_today()
click to toggle source
# File lib/timesheets/commands/status.rb, line 28 def total_time_today active_time(todays_entries) end