Class: QuickAndRuby::Date::DateTimeArgs

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

Overview

argv parser for datetime utility

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

Constant Summary collapse

DEFAULT_FORMAT =
'%Y-%m-%dT%H:%M:%S.%3NZ'
DEFAULT_INCR =
'1d'
DEFAULT_ZONE =
DateTime.now.zone

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_begin: DateTime.now, date_end: nil, incr: DEFAULT_INCR, format: DEFAULT_FORMAT, zone: DEFAULT_ZONE) ⇒ DateTimeArgs

Returns a new instance of DateTimeArgs.



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

def initialize(date_begin: DateTime.now, date_end: nil,
               incr: DEFAULT_INCR,
               format: DEFAULT_FORMAT,
               zone: DEFAULT_ZONE)
  @date_begin = date_begin
  @date_end = date_end
  @incr = incr
  @format = format
  @zone = zone
end

Instance Attribute Details

#date_beginObject (readonly)

Returns the value of attribute date_begin.



19
20
21
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 19

def date_begin
  @date_begin
end

#date_endObject (readonly)

Returns the value of attribute date_end.



19
20
21
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 19

def date_end
  @date_end
end

#formatObject (readonly)

Returns the value of attribute format.



19
20
21
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 19

def format
  @format
end

#incrObject (readonly)

Returns the value of attribute incr.



19
20
21
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 19

def incr
  @incr
end

#zoneObject (readonly)

Returns the value of attribute zone.



19
20
21
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 19

def zone
  @zone
end

Class Method Details

.load(argv = ARGV) ⇒ Object



41
42
43
44
45
46
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 41

def load(argv = ARGV)
  options = new
  parser(options).parse!(argv.clone)
  puts options
  options
end

Instance Method Details

#want_incr?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 36

def want_incr?
  date_begin && !date_end
end

#want_range?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/quick_and_ruby/date/date_time_args.rb', line 32

def want_range?
  date_begin && date_end
end