Module: Arstotzka::TypeCast
Overview
Concern with all the type cast methods to be used by Wrapper
Usage of typecast is defined by the configuration of MethodBuilder by the usage of option type
TypeCast can also be extended to include more types
Supported types:
-
integer
-
string
-
float
-
symbol
Instance Method Summary collapse
-
#to_float(value) ⇒ Float
Converts value to float.
-
#to_integer(value) ⇒ Integer
Converts a value to integer.
-
#to_string(value) ⇒ String
Converts value to string.
-
#to_symbol(value) ⇒ Symbol
Converts value to Symbol.
Instance Method Details
#to_float(value) ⇒ Float
Converts value to float
151 152 153 |
# File 'lib/arstotzka/type_cast.rb', line 151 def to_float(value) value.to_s.to_f if value.present? end |
#to_integer(value) ⇒ Integer
Converts a value to integer
95 96 97 |
# File 'lib/arstotzka/type_cast.rb', line 95 def to_integer(value) value.to_s.to_i if value.present? end |
#to_string(value) ⇒ String
Converts value to string
124 125 126 |
# File 'lib/arstotzka/type_cast.rb', line 124 def to_string(value) value.to_s end |
#to_symbol(value) ⇒ Symbol
Converts value to Symbol
178 179 180 |
# File 'lib/arstotzka/type_cast.rb', line 178 def to_symbol(value) value.to_s.to_sym if value.present? end |