Class: Skit::Serialization::Processor::Float

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/skit/serialization/processor/float.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #traverse

Constructor Details

This class inherits a constructor from Skit::Serialization::Processor::Base

Class Method Details

.handles?(type_spec) ⇒ Boolean

Returns:



11
12
13
# File 'lib/skit/serialization/processor/float.rb', line 11

def self.handles?(type_spec)
  type_spec == ::Float
end

Instance Method Details

#deserialize(value, path: Path.new) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/skit/serialization/processor/float.rb', line 23

def deserialize(value, path: Path.new)
  case value
  when ::Float
    value
  when ::Integer
    value.to_f
  else
    raise DeserializeError.new("Expected Float or Integer, got #{value.class}", path: path)
  end
end

#serialize(value, path: Path.new) ⇒ Object

Raises:



16
17
18
19
20
# File 'lib/skit/serialization/processor/float.rb', line 16

def serialize(value, path: Path.new)
  raise SerializeError.new("Expected Float, got #{value.class}", path: path) unless value.is_a?(::Float)

  value
end