def type_cast(value)
if collection?
return [] if value.nil?
case type
when :string then self.class.hash_to_string_collection(value)
when :text then self.class.hash_to_string_collection(value)
when :integer then self.class.hash_to_integer_collection(value)
when :float then self.class.hash_to_float_collection(value)
when :decimal then self.class.hash_to_decimal_collection(value)
when :datetime then self.class.hash_to_time_collection(value)
when :timestamp then self.class.hash_to_time_collection(value)
when :time then self.class.hash_to_dummy_time_collection(value)
when :date then self.class.hash_to_date_collection(value)
when :binary then self.class.hash_to_string_collection(value)
when :boolean then self.class.hash_to_boolean_collection(value)
when :map then value
when :object then value
else hash_to_embedded_collection(value)
end
else
casted_value =
case type
when :string then value
when :text then value
when :integer then value.to_i rescue value ? 1 : 0
when :float then value.to_f rescue value ? 1.0 : 0.0
when :decimal then self.class.value_to_decimal(value)
when :datetime then self.class.string_to_time(value)
when :timestamp then self.class.string_to_time(value)
when :time then self.class.string_to_dummy_time(value)
when :date then self.class.string_to_date(value)
when :binary then self.class.binary_to_string(value)
when :boolean then self.class.value_to_boolean(value)
when :map then value
when :object then value
else hash_to_embedded(value)
end
casted_value.is_a?(klass) ? casted_value : nil
end
end