Class: Hyrax::Ingest::Transformer::ToDate

Inherits:
Base
  • Object
show all
Defined in:
lib/hyrax/ingest/transformer/to_date.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orig_format) ⇒ ToDate

Returns a new instance of ToDate.



9
10
11
# File 'lib/hyrax/ingest/transformer/to_date.rb', line 9

def initialize(orig_format)
  @orig_format = orig_format.to_sym
end

Instance Attribute Details

#orig_formatObject (readonly)

Returns the value of attribute orig_format.



7
8
9
# File 'lib/hyrax/ingest/transformer/to_date.rb', line 7

def orig_format
  @orig_format
end

Instance Method Details

#transform(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hyrax/ingest/transformer/to_date.rb', line 13

def transform(value)
  return transform_multiple(value) if value.respond_to?(:each)
  case orig_format
  when :from_timestamp_with_ms
    DateTime.strptime(value, '%Q')
  when :"from_yyyy-mm-dd"
    DateTime.parse(value)
  else
    raise Hyrax::Ingest::Errors::UnrecognizedTransformOption.new(orig_format)
  end
end