Class: Dsu::Subcommands::Import

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

#allObject



29
30
31
32
33
# File 'lib/dsu/subcommands/import.rb', line 29

def all
  options = configuration.to_h.merge(self.options).with_indifferent_access
  Views::Import.new(presenter: all_presenter(import_file_path: options[:import_file],
    options: options), options: options).render
end

#datesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dsu/subcommands/import.rb', line 45

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

  Views::ImportDates.new(presenter: dates_presenter_for(from: times.min,
    to: times.max,
    import_file_path: options[:import_file],
    options: options), options: options).render
rescue ArgumentError => e
  Views::Shared::Error.new(messages: e.message).render
end