Class: Hotfile::Date
- Inherits:
-
Object
- Object
- Hotfile::Date
- Defined in:
- lib/hotfile/date.rb
Overview
Parses a string date into a Date object
Instance Method Summary collapse
-
#initialize(date_string) ⇒ Date
constructor
A new instance of Date.
- #to_date ⇒ Object
Constructor Details
#initialize(date_string) ⇒ Date
Returns a new instance of Date.
8 9 10 |
# File 'lib/hotfile/date.rb', line 8 def initialize(date_string) @raw_value = date_string.to_s.strip end |
Instance Method Details
#to_date ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hotfile/date.rb', line 12 def to_date return nil if @raw_value.delete('0') == '' case @raw_value.length when 0 then nil when 5 then ::Date.strptime(@raw_value, '%d%b') when 6 then ::Date.strptime(@raw_value, '%y%m%d') when 7 then ::Date.strptime(@raw_value, '%d%b%y') when 8 then ::Date.strptime(@raw_value, '%Y%m%d') else raise NotImplementedError("Unknown date format: #{@raw_value}") end end |