Class: TempestTime::Commands::List

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

Instance Method Summary collapse

Methods inherited from TempestTime::Command

#command, #date_prompt, #execute, #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, #dates_in_range, #end_of_week, #formatted_date, #formatted_date_range, #formatted_time, #formatted_time_for_input, #formatted_time_long, #future_dates, #parsed_time, #past_dates, #past_week_selections, #week_beginnings, #week_dates

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



9
10
11
12
# File 'lib/tempest_time/commands/list.rb', line 9

def initialize(options)
  @user = options[:user]
  @dates = options[:date] ? [Date.parse(options[:date])] : nil
end

Instance Method Details

#execute!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tempest_time/commands/list.rb', line 14

def execute!
  @dates ||= date_prompt(
    'Please select the dates you wish to view.',
    days_before: 13,
    days_after: 13
  ).sort
  @dates.each do |date|
    with_spinner("Retrieving logs for #{pastel.yellow(formatted_date(date))}...") do |spin|
      @response = TempoAPI::Requests::ListWorklogs.new(
        date,
        end_date: nil,
        requested_user: @user
      ).send_request
      spin.stop(pastel.green('Done!'))
      prompt.say(render_table)
      prompt.say(
        'Total Time Logged: '\
        "#{pastel.green("#{@response.total_hours_spent} hours")}"
      )
    end
  end
end