Module: ActiveFedora::Attributes::Serializers

Defined in:
lib/active_fedora/attributes/serializers.rb

Instance Method Summary collapse

Instance Method Details

#attributes=(params) ⇒ Object

set a hash of attributes on the object

Parameters:

  • params (Hash)

    the properties to set on the object


25
26
27
# File 'lib/active_fedora/attributes/serializers.rb', line 25

def attributes=(params)
  super(deserialize_dates_from_form(params))
end

#deserialize_dates_from_form(params) ⇒ Hash

This allows you to use date_select helpers in rails views

Parameters:

  • params (Hash)

    parameters hash

Returns:

  • (Hash)

    a parameters list with the date select parameters replaced with dates


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_fedora/attributes/serializers.rb', line 8

def deserialize_dates_from_form(params)
  dates = {}
  params.each do |key, value| 
    if data = key.to_s.match(/^(.+)\((\d)i\)$/)
      dates[data[1]] ||= {}
      dates[data[1]][data[2]] = value
      params.delete(key)
    end
  end
  dates.each do |key, value|
    params[key] = [value['1'], value['2'], value['3']].join('-')
  end
  params
end