Module: Swagger
- Defined in:
- lib/swagger/base.rb,
lib/swagger/rack.rb
Defined Under Namespace
Modules: RackHelpers Classes: Base
Class Method Summary collapse
-
.cast(value, type = "string") ⇒ Object
Casts a string value to the ruby datatype as definied in the swagger spec.
Class Method Details
.cast(value, type = "string") ⇒ Object
Casts a string value to the ruby datatype as definied in the swagger spec
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/swagger/base.rb', line 5 def self.cast(value, type = "string") raise ArgumentError, "#{value} is not a string" unless value.is_a?(String) case type when "string" value when "integer" raise ArgumentError, "#{value} is not an integer" unless value =~ /^-?\d+$/ value.to_i when "number" raise ArgumentError, "#{value} is not a float" unless value =~ /^-?\d+(?:\.\d+)?$/ value.to_f else raise NotImplementedError end end |