Module: Happy::Request::DateParameterConverter

Defined in:
lib/happy/request/date_parameter_converter.rb

Class Method Summary collapse

Class Method Details

.convert!(params) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/happy/request/date_parameter_converter.rb', line 5

def convert!(params)
  params.each do |k, v|
    if looks_like_a_date?(v)
      params[k] = convert_to_date(v)
    elsif v.is_a? Hash
      convert!(v)
    end
  end
end

.convert_to_date(v) ⇒ Object



19
20
21
# File 'lib/happy/request/date_parameter_converter.rb', line 19

def convert_to_date(v)
  DateTime.new(v['year'].to_i, v['month'].to_i, v['day'].to_i, v['hour'].to_i, v['minute'].to_i, v['second'].to_i)
end

.looks_like_a_date?(v) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/happy/request/date_parameter_converter.rb', line 15

def looks_like_a_date?(v)
  v.is_a?(Hash) && v.has_key?('year') && v.has_key?('month') && v.has_key?('day')
end