Class: Qif::DateFormat
- Inherits:
-
Object
- Object
- Qif::DateFormat
- Defined in:
- lib/qif/date_format.rb
Instance Attribute Summary collapse
-
#format(date) ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
-
#initialize(format = 'dd/mm/yyyy') ⇒ DateFormat
constructor
A new instance of DateFormat.
- #parse(date) ⇒ Object
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 |