class Timesheets::Commands::Base
Attributes
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/timesheets/commands/base.rb, line 10 def initialize(options = {}) @options = options end
run(options = {})
click to toggle source
# File lib/timesheets/commands/base.rb, line 6 def self.run(options = {}) new(options).run end
Private Instance Methods
entries()
click to toggle source
# File lib/timesheets/commands/base.rb, line 28 def entries @entries ||= rows.map {|row| row.map {|dt| DateTime.parse(dt || Time.now.to_s).to_time } } end
filepath()
click to toggle source
# File lib/timesheets/commands/base.rb, line 44 def filepath File.expand_path(ENV['TIMESHEETS_FILEPATH'] || '~/.timesheets.csv') end
hours_in_entry(entry)
click to toggle source
# File lib/timesheets/commands/base.rb, line 24 def hours_in_entry(entry) entry.map(&:to_i).reverse.reduce(:-) / 3600.0 end
logger()
click to toggle source
# File lib/timesheets/commands/base.rb, line 16 def logger @logger ||= Timesheets::Logger.new end
rows()
click to toggle source
# File lib/timesheets/commands/base.rb, line 40 def rows @rows ||= CSV.read(filepath)[1..-1] end
session_in_progress?()
click to toggle source
# File lib/timesheets/commands/base.rb, line 20 def session_in_progress? rows.last.last.nil? end
today()
click to toggle source
# File lib/timesheets/commands/base.rb, line 36 def today @today ||= Time.new.strftime('%Y%m%d') end
todays_entries()
click to toggle source
# File lib/timesheets/commands/base.rb, line 32 def todays_entries entries.select {|entry| entry.first.strftime('%Y%m%d') == today } end