Class: Dsu::Subcommands::Delete

Inherits:
BaseSubcommand show all
Includes:
Dsu::Support::CommandOptions::TimeMnemonic, Dsu::Support::TimeFormatable
Defined in:
lib/dsu/subcommands/delete.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



51
52
53
54
55
56
57
58
59
60
# File 'lib/dsu/subcommands/delete.rb', line 51

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
  delete_entry_groups_if times: [time], options: options
rescue ArgumentError => e
  Views::Shared::Error.new(messages: e.message).render
end

#datesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dsu/subcommands/delete.rb', line 69

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

  times = times_sort(times: times, entries_display_order: options[:entries_display_order])
  delete_entry_groups_if times: times, options: options
rescue ArgumentError => e
  Views::Shared::Error.new(messages: e.message).render
end

#todayObject



28
29
30
# File 'lib/dsu/subcommands/delete.rb', line 28

def today
  delete_entry_groups_if times: [Time.now], options: options
end

#tomorrowObject



35
36
37
# File 'lib/dsu/subcommands/delete.rb', line 35

def tomorrow
  delete_entry_groups_if times: [Time.now.tomorrow], options: options
end

#yesterdayObject



42
43
44
# File 'lib/dsu/subcommands/delete.rb', line 42

def yesterday
  delete_entry_groups_if times: [Time.now.yesterday], options: options
end