Class: TempestTime::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::FormattingHelper, Helpers::GitHelper, Helpers::TimeHelper
Defined in:
lib/tempest_time/command.rb

Instance Method Summary collapse

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

Instance Method Details

#commandObject



24
25
26
27
# File 'lib/tempest_time/command.rb', line 24

def command
  require 'tty-command'
  TTY::Command.new
end

#date_prompt(message, past_days = 6) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/tempest_time/command.rb', line 49

def date_prompt(message, past_days = 6)
  require 'tty-prompt'
  dates = past_date_selections(past_days)
  TTY::Prompt.new.select(
    message,
    dates,
    per_page: 5
  )
end

#executeObject

Raises:

  • (NotImplementedError)


17
18
19
20
21
22
# File 'lib/tempest_time/command.rb', line 17

def execute(*)
  raise(
      NotImplementedError,
      "#{self.class}##{__method__} must be implemented"
  )
end

#pastel(**options) ⇒ Object



29
30
31
32
# File 'lib/tempest_time/command.rb', line 29

def pastel(**options)
  require 'pastel'
  Pastel.new(options)
end

#prompt(**options) ⇒ Object



34
35
36
37
# File 'lib/tempest_time/command.rb', line 34

def prompt(**options)
  require 'tty-prompt'
  TTY::Prompt.new(options)
end

#spinnerObject



59
60
61
62
# File 'lib/tempest_time/command.rb', line 59

def spinner
  require 'tty-spinner'
  TTY::Spinner
end

#tableObject



64
65
66
67
# File 'lib/tempest_time/command.rb', line 64

def table
  require 'tty-table'
  TTY::Table
end

#week_prompt(message, past_weeks = 51) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/tempest_time/command.rb', line 39

def week_prompt(message, past_weeks = 51)
  require 'tty-prompt'
  weeks = past_week_selections(past_weeks)
  TTY::Prompt.new.select(
    message,
    weeks,
    per_page: 5
  )
end

#with_spinner(message, format = :pong) {|s| ... } ⇒ Object

Yields:

  • (s)


69
70
71
72
73
# File 'lib/tempest_time/command.rb', line 69

def with_spinner(message, format = :pong)
  s = spinner.new(":spinner #{message}", format: format)
  s.auto_spin
  yield(s)
end

#with_success_fail_spinner(message, format = :spin_3) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/tempest_time/command.rb', line 75

def with_success_fail_spinner(message, format = :spin_3)
  s = spinner.new(":spinner #{message}", format: format)
  s.auto_spin
  response = yield
  if response.success?
    s.success(pastel.green(response.message))
  else
    s.error(pastel.red(response.message))
  end
end