Class: Commands::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/detom/commands/record.rb

Constant Summary collapse

CLIENT_REQUIRED_MESSAGE =
"Cannot log time without a client. Either provide <client> to detom record, or configure a value for client in this directory using detom set."
DATE_FORMAT_MESSAGE =
"Day/month is an unrecognised format. Use `%d-%m` format"
TIME_TO_LOG_FORMAT_MESSAGE =
"Time must be provided in minutes or hours, e,g 40m or 3h"

Instance Method Summary collapse

Constructor Details

#initialize(store, local_config) ⇒ Record

Returns a new instance of Record.



7
8
9
10
# File 'lib/detom/commands/record.rb', line 7

def initialize(store, local_config)
  @store = store
  @local_config = local_config
end

Instance Method Details

#call(time_to_log, client_name = nil, day_month = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/detom/commands/record.rb', line 12

def call(time_to_log, client_name=nil, day_month=nil)
  client = client_for client_name

  date_stamp = format(day_month)
  
  client[date_stamp] = [] unless client[date_stamp]

  client[date_stamp] << minutes_from(time_to_log)

  @store.save!
  $stdout.puts "Logged #{time_to_log} for #{client_name}"
end