Class: Restio::Util::Caster::Default

Inherits:
Generic show all
Defined in:
lib/restio/util/caster/default.rb

Constant Summary collapse

RE_FLOAT =
/^[0-9]+\.[0-9]+$/
RE_INT =
/^[0-9]+$/
RE_UUID =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/

Instance Method Summary collapse

Methods inherited from Generic

#cast

Instance Method Details

#map(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/restio/util/caster/default.rb', line 11

def map value
  return value if value.nil?
  return value unless value.is_a? String
  return true if value == "true"
  return false if value == "false"
  return value.to_i if value.match(RE_INT)
  return value.to_f if value.match(RE_FLOAT)
  return UUIDTools::UUID.parse(value) if value.match(RE_UUID)
  nil
end