Class: Valkyrie::Persistence::Shared::JSONValueMapper::DateValue

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/shared/json_value_mapper.rb

Overview

Converts Date strings to ‘DateTime`

Instance Attribute Summary

Attributes inherited from ValueMapper

#calling_mapper, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueMapper

for, #initialize, register

Constructor Details

This class inherits a constructor from Valkyrie::ValueMapper

Class Method Details

.handles?(value) ⇒ Boolean

Determines whether or not a value is an ISO 8601 datestamp String

    1. 1970-01-01

rubocop:disable Metrics/CyclomaticComplexity

Parameters:

  • value (Object)

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
149
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 141

def self.handles?(value)
  return false unless value.is_a?(String)
  return false unless value[4] == "-" && value[10] == "T"
  year = value.to_s[0..3]
  return false unless year.length == 4 && year.to_i.to_s == year
  DateTime.iso8601(value)
rescue
  false
end

Instance Method Details

#resultTime

Generates a Time object in the UTC from the datestamp string value

Returns:

  • (Time)


154
155
156
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 154

def result
  DateTime.iso8601(value).new_offset(0)
end