Class: Qif::DateFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/qif/date_format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format = 'dd/mm/yyyy') ⇒ DateFormat

Returns a new instance of DateFormat.



7
8
9
# File 'lib/qif/date_format.rb', line 7

def initialize(format = 'dd/mm/yyyy')
  @format = format
end

Instance Attribute Details

#format(date) ⇒ Object (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/qif/date_format.rb', line 5

def format
  @format
end

Instance Method Details

#parse(date) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/qif/date_format.rb', line 11

def parse(date)
  regex = convert_format_to_regex
  order = date_order
  
  if match = regex.match(date)
    Time.mktime(*%w(y m d).map{|t| match[order.index(t) + 1].to_i })
  end
end