class RealPage::AttributeParser::Date

Parse the response value of a date attribute

Constants

FORMAT

RealPage responds with multiple date formats. This is one format that Date.parse will not parse correctly, so we need special handling

Public Instance Methods

parse() click to toggle source

@return [Date] the parsed attribute value

# File lib/real_page/attribute_parser/date.rb, line 13
def parse
  return if value == ''
  if value =~ %r[/]
    ::Date.strptime(value, FORMAT)
  else
    # RealPage 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