Sha256: 98645274e8a473e71d12c98fd9d55b19ce4ca18839d5b5a6b24b9114591550af

Contents?: true

Size: 663 Bytes

Versions: 14

Compression:

Stored size: 663 Bytes

Contents

module HappyHelpers
  module Utils
    module DateParameterConverter
      class << self
        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

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

        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
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
happy-helpers-0.1.0.pre12 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre11 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre10 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre9 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre8 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre7 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre6 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.6 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.5 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.4 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.3 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.2 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.1.0.pre.1 lib/happy-helpers/utils/date_parameter_converter.rb
happy-helpers-0.0.2 lib/happy-helpers/utils/date_parameter_converter.rb