Module: AspireBudget::Utils
- Defined in:
- lib/aspire_budget/utils.rb
Class Method Summary collapse
-
.parse_date(value) ⇒ Date
Parses a value to a date object.
-
.parse_status(value) ⇒ Symbol
Parses a status icon.
-
.serialize_date(value) ⇒ Float
Parses a value to a serial date.
-
.serialize_status(value) ⇒ String
Serialize a status symbol.
Class Method Details
.parse_date(value) ⇒ Date
Parses a value to a date object
11 12 13 14 15 16 |
# File 'lib/aspire_budget/utils.rb', line 11 def parse_date(value) return parse_serial_date(value) if value.is_a?(Numeric) return value.to_date if value.respond_to?(:to_date) raise 'Unsupported date format' end |
.parse_status(value) ⇒ Symbol
Parses a status icon
34 35 36 |
# File 'lib/aspire_budget/utils.rb', line 34 def parse_status(value) TRANSACTION_STATUS_MAPPING.fetch(value, nil) end |
.serialize_date(value) ⇒ Float
Parses a value to a serial date
21 22 23 24 25 26 27 28 29 |
# File 'lib/aspire_budget/utils.rb', line 21 def serialize_date(value) return Float(value) if value.is_a?(Numeric) && value >= 0 value = value.to_date if value.respond_to?(:to_date) raise 'Unsupported date value' unless value.is_a?(Date) raise "Date should be after #{LOTUS_DAY_ONE}" if LOTUS_DAY_ONE > value Float(value - LOTUS_DAY_ONE) end |
.serialize_status(value) ⇒ String
Serialize a status symbol
41 42 43 |
# File 'lib/aspire_budget/utils.rb', line 41 def serialize_status(value) TRANSACTION_STATUS_MAPPING.key(value) || '' end |