Sha256: 5c5b31c0fab1eca356f581a6d749077872fb53d57e5234203531789be69d676b

Contents?: true

Size: 744 Bytes

Versions: 14

Compression:

Stored size: 744 Bytes

Contents

module Rasti
  class Form
    module Types
      class Hash
        
        include Castable

        attr_reader :key_type, :value_type

        def self.[](key_type, value_type)
          new key_type, value_type
        end

        def to_s
          "#{self.class}[#{key_type}, #{value_type}]"
        end
        alias_method :inspect, :to_s

        private

        def initialize(key_type, value_type)
          @key_type = key_type
          @value_type = value_type
        end

        def valid?(value)
          value.is_a? ::Hash
        end

        def transform(value)
          value.each_with_object({}) do |(k,v),h| 
            h[key_type.cast k] = value_type.cast v
          end
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/hash.rb
rasti-form-3.1.1 lib/rasti/form/types/hash.rb
rasti-form-3.1.0 lib/rasti/form/types/hash.rb
rasti-form-3.0.0 lib/rasti/form/types/hash.rb
rasti-form-2.2.0 lib/rasti/form/types/hash.rb
rasti-form-2.1.0 lib/rasti/form/types/hash.rb
rasti-form-2.0.0 lib/rasti/form/types/hash.rb
rasti-form-1.1.1 lib/rasti/form/types/hash.rb
rasti-form-1.1.0 lib/rasti/form/types/hash.rb
rasti-form-1.0.3 lib/rasti/form/types/hash.rb
rasti-form-1.0.2 lib/rasti/form/types/hash.rb
rasti-form-1.0.1 lib/rasti/form/types/hash.rb
rasti-form-1.0.0 lib/rasti/form/types/hash.rb
rasti-form-0.1.0 lib/rasti/form/types/hash.rb