Sha256: 574b79cc3ee00a2456fc3faf1c0334bb30478b2ad754cf46619a5015e5973b4b

Contents?: true

Size: 554 Bytes

Versions: 27

Compression:

Stored size: 554 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Date
      module Casters
        class Hash < Value::Caster
          def applicable?(hash)
            hash.is_a?(::Hash) && hash.keys.size == 3 && (hash.keys.map(&:to_s).sort == %w[day month year])
          end

          def applies_message
            "be a Hash with :year, :month, and :day keys"
          end

          def cast(hash)
            hash = Util.symbolize_keys(hash)

            ::Date.new(hash[:year], hash[:month], hash[:day])
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.6 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.5 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.4 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.3 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.2 projects/builtin_types/src/date/casters/hash.rb
foobara-0.0.1 projects/builtin_types/src/date/casters/hash.rb