Module: RequireDate

Defined in:
lib/require_date.rb

Constant Summary collapse

VERSION =
'0.0.2'
ARGUMENT_LIST =
ARGV.dup
FORMATS =
{
  :date => Regexp.union(/\A(\d{4})-(\d{2})-(\d{2})\z/, /\A(\d{4})(\d{2})(\d{2})\z/),
  :month_group => Regexp.union(/\A(\d{4})-(\d{2})\z/, /\A(\d{4})(\d{2})\z/)
}

Class Method Summary collapse

Class Method Details

.next(format = FORMATS[:date], &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/require_date.rb', line 14

def self.next(format = FORMATS[:date], &block)
  ARGUMENT_LIST.each_with_index do |x, i|
    if x[format]
      return_value = x
      ARGUMENT_LIST.delete_at(i)
      return return_value
    end
  end

  if block_given?
    yield block
  else
    raise ArgumentError, "No day remaining to pull from ARGV"
  end
end

.try_parse(date) ⇒ Object



30
31
32
33
# File 'lib/require_date.rb', line 30

def self.try_parse(date)
  return date if Date === date
  return Date.parse(date)
end