Class: Todo::Support::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/todo/support/date.rb

Constant Summary collapse

NUMS =
[:one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten]
MONTHS =
[:jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]
WDAYS =
[:sun, :mon, :tue, :wed, :thu, :fri, :sat]
FORMAT =
'%Y-%m-%d'
MSGS =
{ unknown: 'Unrecognized identifier: %s' }
SEP =
'(?: |_|\-|\.)'
AGO =
/^(\d+|#{NUMS.join('|')})#{SEP}(days?|weeks?|months?|years?)#{SEP}ago$/
LAST =
/^last#{SEP}(#{MONTHS.join('|')}|#{WDAYS.join('|')})/
DATE =
/\d{4}-\d{2}-\d{2}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = ::Date.today) ⇒ Date

Returns a new instance of Date.



19
20
21
# File 'lib/todo/support/date.rb', line 19

def initialize(date = ::Date.today)
  @date = date.to_date
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



17
18
19
# File 'lib/todo/support/date.rb', line 17

def date
  @date
end

Instance Method Details

#format(str, opts = {}) ⇒ Object



23
24
25
# File 'lib/todo/support/date.rb', line 23

def format(str, opts = {})
  apply(str).strftime(opts[:format] || FORMAT)
end