Class: QuickAndRuby::Date::DateTimeCli

Inherits:
Object
  • Object
show all
Defined in:
lib/quick_and_ruby/date/date_time_cli.rb

Overview

cli / main class for datetime utility

usage example:
- datetime -z <zone> -i <incr> -f "<format>" <from>|now <to>|now
- datetime -z <zone> -i <incr> -f "<format>" <from>|now

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV, args_loader = QuickAndRuby::Date::DateTimeArgs) ⇒ DateTimeCli

Returns a new instance of DateTimeCli.



12
13
14
15
# File 'lib/quick_and_ruby/date/date_time_cli.rb', line 12

def initialize(argv = ARGV, args_loader = QuickAndRuby::Date::DateTimeArgs)
  @argv = argv || []
  @args_loader = args_loader
end

Instance Method Details

#argsObject



35
36
37
# File 'lib/quick_and_ruby/date/date_time_cli.rb', line 35

def args
  @args ||= args_loader.load(argv)
end

#runObject



17
18
19
20
# File 'lib/quick_and_ruby/date/date_time_cli.rb', line 17

def run
  run_range if args.want_range?
  run_incr if args.want_incr?
end

#run_incrObject



31
32
33
# File 'lib/quick_and_ruby/date/date_time_cli.rb', line 31

def run_incr
  puts :RUN_INCR
end

#run_rangeObject



22
23
24
25
26
27
28
29
# File 'lib/quick_and_ruby/date/date_time_cli.rb', line 22

def run_range
  puts :RUN_RANGE
  time_cursor = args.date_begin
  while time_cursor <= args.date_end
    puts time_cursor.strftime(args.format)
    time_cursor.increment(**args.incr)
  end
end