Module: DeepL::Utils::NumberParser
Overview
Reads numbers from API responses without failing on unexpected values.
Instance Method Summary collapse
-
#count(value) ⇒ Integer
The value if it is an Integer, otherwise 0.
-
#minutes(value) ⇒ Float
The value as a Float if it is numeric, otherwise 0.0.
-
#optional_count(value) ⇒ Integer?
The value if it is an Integer, otherwise nil.
-
#optional_minutes(value) ⇒ Float?
The value as a Float if it is numeric, otherwise nil.
Instance Method Details
#count(value) ⇒ Integer
Returns The value if it is an Integer, otherwise 0.
14 15 16 |
# File 'lib/deepl/utils/number_parser.rb', line 14 def count(value) value.is_a?(Integer) ? value : 0 end |
#minutes(value) ⇒ Float
Returns The value as a Float if it is numeric, otherwise 0.0.
19 20 21 |
# File 'lib/deepl/utils/number_parser.rb', line 19 def minutes(value) value.is_a?(Numeric) ? value.to_f : 0.0 end |
#optional_count(value) ⇒ Integer?
Returns The value if it is an Integer, otherwise nil.
29 30 31 |
# File 'lib/deepl/utils/number_parser.rb', line 29 def optional_count(value) value.is_a?(Integer) ? value : nil end |
#optional_minutes(value) ⇒ Float?
Returns The value as a Float if it is numeric, otherwise nil.
24 25 26 |
# File 'lib/deepl/utils/number_parser.rb', line 24 def optional_minutes(value) value.is_a?(Numeric) ? value.to_f : nil end |