Class: Dsu::Subcommands::List

Inherits:
BaseSubcommand show all
Includes:
Dsu::Support::CommandOptions::TimeMnemonic, Dsu::Support::TimeFormatable
Defined in:
lib/dsu/subcommands/list.rb

Constant Summary

Constants included from Dsu::Support::CommandOptions::TimeMnemonics

Dsu::Support::CommandOptions::TimeMnemonics::RELATIVE_REGEX, Dsu::Support::CommandOptions::TimeMnemonics::TODAY, Dsu::Support::CommandOptions::TimeMnemonics::TOMORROW, Dsu::Support::CommandOptions::TimeMnemonics::YESTERDAY

Instance Method Summary collapse

Methods included from Dsu::Support::TimeFormatable

dd_mm_yyyy, formatted_time, mm_dd, mm_dd_yyyy, timezone_for, yyyy_mm_dd, yyyy_mm_dd_or_through_for

Methods included from Dsu::Support::CommandOptions::TimeMnemonic

relative_time_mnemonic?, time_from_mnemonic, time_from_mnemonic!, time_mnemonic?

Methods included from Dsu::Support::Ask

#ask_while, #yes?

Methods inherited from BaseCLI

date_option_description, exit_on_failure?, #initialize, mnemonic_option_description

Methods included from Dsu::Support::TimesSortable

#sorted_dsu_times_for, #times_for, #times_sort

Methods included from Dsu::Support::CommandHookable

included

Methods included from Dsu::Support::CommandHelpColorizable

included

Methods included from Dsu::Support::ColorThemable

apply_theme, #prompt_with_options

Constructor Details

This class inherits a constructor from Dsu::BaseCLI

Instance Method Details

#date(date_or_mnemonic) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dsu/subcommands/list.rb', line 56

def date(date_or_mnemonic)
  time = if time_mnemonic?(date_or_mnemonic)
    time_from_mnemonic(command_option: date_or_mnemonic)
  else
    Time.parse(date_or_mnemonic)
  end
  times = sorted_dsu_times_for(times: [time, time.yesterday])
  presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
  Views::EntryGroup::List.new(presenter: presenter).render
rescue ArgumentError => e
  Views::Shared::Error.new(messages: e.message).render
end

#datesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dsu/subcommands/list.rb', line 77

def dates
  options = configuration.to_h.merge(self.options).with_indifferent_access
  times, errors = Support::CommandOptions::DsuTimes.dsu_times_for(from_option: options[:from], to_option: options[:to]) # rubocop:disable Layout/LineLength
  if errors.any?
    Views::Shared::Error.new(messages: errors).render
    return
  end

  # NOTE: special sort here, unlike the other commands where rules for
  # displaying DSU entries are applied; this is more of a list command.
  times = times_sort(times: times, entries_display_order: options[:entries_display_order])
  presenter = Presenters::EntryGroup::List::DatesPresenter.new(times: times, options: options)
  Views::EntryGroup::List.new(presenter: presenter).render
rescue ArgumentError => e
  Views::Shared::Error.new(messages: e.message).render
end

#todayObject



27
28
29
30
31
32
# File 'lib/dsu/subcommands/list.rb', line 27

def today
  time = Time.now
  times = sorted_dsu_times_for(times: [time.yesterday, time])
  presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
  Views::EntryGroup::List.new(presenter: presenter).render
end

#tomorrowObject



36
37
38
39
40
41
# File 'lib/dsu/subcommands/list.rb', line 36

def tomorrow
  time = Time.now
  times = sorted_dsu_times_for(times: [time, time.tomorrow])
  presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
  Views::EntryGroup::List.new(presenter: presenter).render
end

#yesterdayObject



45
46
47
48
49
50
# File 'lib/dsu/subcommands/list.rb', line 45

def yesterday
  time = Time.now
  times = sorted_dsu_times_for(times: [time.yesterday, time.yesterday.yesterday])
  presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
  Views::EntryGroup::List.new(presenter: presenter).render
end