Class: Amsi::AttributeParser::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/amsi/attribute_parser/date.rb

Overview

Parse the response value of a date attribute

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Amsi::AttributeParser::Base

Instance Method Details

#parseDate

Returns the parsed attribute value.

Returns:

  • (Date)

    the parsed attribute value



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/amsi/attribute_parser/date.rb', line 13

def parse
  return if value == ''

  if value =~ %r{/}
    ::Date.strptime(value, FORMAT)
  else
    # AMSI sometimes returns 0001-01-01 for dates, which appears to be
    # their representation of a NULL value.
    date = ::Date.parse(value)
    date.year == 1 ? nil : date
  end
rescue ArgumentError
  raise Error::InvalidResponse, "Invalid date response value: #{value}"
end