class NumbersAndWords::Wrappers::Float
Constants
- ZERO_SYMBOL
Attributes
Public Class Methods
Source
# File lib/numbers_and_words/wrappers/float.rb, line 10 def initialize(number) @number = number end
Public Instance Methods
Source
# File lib/numbers_and_words/wrappers/float.rb, line 14 def to_words(options = {}) @options = options words = [] words << integral_part_with(options) words << fractional_part_with(options) unless fractional_part_is_nil? NumbersAndWords::WordsArray.new(words).join options end
Private Instance Methods
Source
# File lib/numbers_and_words/wrappers/float.rb, line 52 def fractional_options length = precision || fractional_part.length { fractional: { length: } } end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 34 def fractional_part part = parts.last part += ZERO_SYMBOL * (precision - part.length) if precision part end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 57 def fractional_part_is_nil? fractional_part.to_i.zero? end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 44 def fractional_part_with(options) fractional_part.to_i.to_words options.merge(fractional_options) end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 48 def integral_options { integral: {} } end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 30 def integral_part parts.first end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 40 def integral_part_with(options) integral_part.to_i.to_words options.merge(integral_options) end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 26 def parts number.to_s.split '.' end
Source
# File lib/numbers_and_words/wrappers/float.rb, line 61 def precision options.fetch(:precision, nil) end