Class: TTY::Conversion::FloatConverter
- Inherits:
-
Object
- Object
- TTY::Conversion::FloatConverter
- Defined in:
- lib/tty/conversion/converter/float.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #convert(value, strict = false) ⇒ Object
-
#initialize(source = String) ⇒ FloatConverter
constructor
A new instance of FloatConverter.
Constructor Details
#initialize(source = String) ⇒ FloatConverter
Returns a new instance of FloatConverter.
11 12 13 14 |
# File 'lib/tty/conversion/converter/float.rb', line 11 def initialize(source = String) @source = source @target = Float end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/tty/conversion/converter/float.rb', line 9 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
7 8 9 |
# File 'lib/tty/conversion/converter/float.rb', line 7 def target @target end |
Instance Method Details
#convert(value, strict = false) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tty/conversion/converter/float.rb', line 17 def convert(value, strict = false) Kernel.send(target.name.to_sym, value.to_s) rescue if strict raise InvalidArgument, "#{value} could not be coerced into #{target.name}" else value.to_f end end |