Class: Valkyrie::Persistence::Solr::ORMConverter::DateTimeValue

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/orm_converter.rb

Overview

Converts a datetime in Solr into a 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

Note:

this determines whether or not this should be mapped to a DateTime object

Determines whether or not a string representation of an Object is prefixed with “datetime-”

Parameters:

  • value (Object)

Returns:

  • (Boolean)


446
447
448
449
450
451
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 446

def self.handles?(value)
  return false unless value.to_s.start_with?("datetime-")
  DateTime.iso8601(value.sub(/^datetime-/, '')).new_offset(0)
rescue
  false
end

Instance Method Details

#resultTime

Parses and casts the Solr field value into a UTC DateTime value

Returns:

  • (Time)


455
456
457
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 455

def result
  DateTime.parse(value.sub(/^datetime-/, '')).new_offset(0)
end