Class: TTY::Conversion::IntegerConverter
- Inherits:
-
Object
- Object
- TTY::Conversion::IntegerConverter
- Defined in:
- lib/tty/conversion/converter/integer.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) ⇒ IntegerConverter
constructor
A new instance of IntegerConverter.
Constructor Details
#initialize(source = String) ⇒ IntegerConverter
Returns a new instance of IntegerConverter.
11 12 13 14 |
# File 'lib/tty/conversion/converter/integer.rb', line 11 def initialize(source = String) @source = source @target = Integer end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/tty/conversion/converter/integer.rb', line 9 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
7 8 9 |
# File 'lib/tty/conversion/converter/integer.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/integer.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_i end end |