Class: CSVPlusPlus::Entities::Date
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/entities/date.rb
Overview
A date value
Constant Summary collapse
- DATE_STRING_REGEXP =
TODO: support time granularity?
%r{^\d{1,2}[/-]\d{1,2}[/-]\d{1,4}?$}
Instance Attribute Summary collapse
-
#value ⇒ Date
readonly
The parsed date.
Class Method Summary collapse
-
.valid_date?(date_string) ⇒ Boolean
Is the given string a valid date?.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #evaluate(_position) ⇒ ::String
-
#initialize(value) ⇒ Date
constructor
A new instance of Date.
Constructor Details
#initialize(value) ⇒ Date
Returns a new instance of Date.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/csv_plus_plus/entities/date.rb', line 32 def initialize(value) super() parsed = begin ::Date.parse(value) rescue ::Date::Error ::Date.strptime(value, '%d/%m/%yyyy') end @value = ::T.let(parsed, ::Date) end |
Instance Attribute Details
#value ⇒ Date (readonly)
The parsed date
9 10 11 |
# File 'lib/csv_plus_plus/entities/date.rb', line 9 def value @value end |
Class Method Details
.valid_date?(date_string) ⇒ Boolean
Is the given string a valid date?
23 24 25 26 27 28 |
# File 'lib/csv_plus_plus/entities/date.rb', line 23 def self.valid_date?(date_string) new(date_string) true rescue ::Date::Error false end |
Instance Method Details
#==(other) ⇒ Boolean
56 57 58 59 60 61 62 63 |
# File 'lib/csv_plus_plus/entities/date.rb', line 56 def ==(other) case other when self.class other.value == @value else false end end |
#evaluate(_position) ⇒ ::String
48 49 50 |
# File 'lib/csv_plus_plus/entities/date.rb', line 48 def evaluate(_position) @value.strftime('%m/%d/%y') end |