Class: TempestTime::Commands::Track

Inherits:
TempestTime::Command show all
Defined in:
lib/tempest_time/commands/track.rb

Instance Method Summary collapse

Methods inherited from TempestTime::Command

#command, #date_prompt, #pastel, #prompt, #spinner, #table, #week_prompt, #with_spinner, #with_success_fail_spinner

Methods included from Helpers::GitHelper

#automatic_issue

Methods included from Helpers::FormattingHelper

#braced, #with_percent_sign

Methods included from Helpers::TimeHelper

#beginning_of_week, #end_of_week, #formatted_date, #formatted_date_range, #formatted_time, #formatted_time_for_input, #formatted_time_long, #parsed_time, #past_date_selections, #past_week_selections, #week_beginnings, #week_dates

Constructor Details

#initialize(time, issues, options) ⇒ Track

Returns a new instance of Track.



11
12
13
14
15
# File 'lib/tempest_time/commands/track.rb', line 11

def initialize(time, issues, options)
  @time = time
  @issues = issues
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tempest_time/commands/track.rb', line 17

def execute(input: $stdin, output: $stdout)
  time = @options[:split] ? parsed_time(@time) / @issues.count : parsed_time(@time)
  issues = @issues.any? ? @issues.map(&:upcase) : [automatic_issue]

  unless @options[:autoconfirm]
    prompt_message = "Track #{formatted_time(time)}, "\
                   "#{billability(@options)}, "\
                   "to #{issues.join(', ')}?"
    abort unless prompt.yes?(prompt_message, convert: :bool)
  end

  issues.each do |issue|
    track_time(time, @options.merge('issue' => issue))
  end
end