class NumberMuncher::Numeric

Constants

ARITHMETIC_OPERATORS

Public Class Methods

new(value) click to toggle source
Calls superclass method
# File lib/number_muncher/numeric.rb, line 7
def initialize(value)
  super(parse(value))
end

Public Instance Methods

round(to = nil) click to toggle source
# File lib/number_muncher/numeric.rb, line 21
def round(to = nil)
  return self unless to

  to = Numeric.new(to)
  raise IllegalRoundValue, 'cannot round to nearest 0' if to.zero?

  to * (self / to).to_f.round
end
to_fraction(**opts) click to toggle source
# File lib/number_muncher/numeric.rb, line 30
def to_fraction(**opts)
  ToFraction.new(opts).call(self)
end
to_r() click to toggle source
# File lib/number_muncher/numeric.rb, line 11
def to_r
  rational
end

Private Instance Methods

parse(value) click to toggle source
# File lib/number_muncher/numeric.rb, line 36
def parse(value)
  Rational(value)

rescue ArgumentError
  Parser.new(value).call.to_r
end