Class: CommandTower::Deserializers::Clients::Types::FloatType

Inherits:
Type
  • Object
show all
Includes:
Singleton
Defined in:
app/deserializers/command_tower/deserializers/clients/types.rb

Instance Method Summary collapse

Instance Method Details

#call(value, path:) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/deserializers/command_tower/deserializers/clients/types.rb', line 137

def call(value, path:)
  return value if value.is_a?(Float)
  return value.to_f if value.is_a?(Integer)

  if value.is_a?(String)
    begin
      return Float(value)
    rescue ArgumentError
      reject!(path, value, "float", "not a numeric string")
    end
  end

  reject!(path, value, "float", "expected Float")
end

#expected_label ⇒ Object



152
153
154
# File 'app/deserializers/command_tower/deserializers/clients/types.rb', line 152

def expected_label
  "float"
end