Module: Slab::NumericExt

Defined in:
lib/slab/numeric.rb

Defined Under Namespace

Classes: DiscountTooBig

Instance Method Summary collapse

Instance Method Details

#commercial_roundObject



27
28
29
# File 'lib/slab/numeric.rb', line 27

def commercial_round
  (self * 100.0).round / 100.0
end

#discount(factor) ⇒ Object

Raises:



10
11
12
13
# File 'lib/slab/numeric.rb', line 10

def discount(factor)
  raise DiscountTooBig if factor > 1
  self * (1.0 - factor)
end

#gross(tax_factor) ⇒ Object



19
20
21
# File 'lib/slab/numeric.rb', line 19

def gross(tax_factor)
  self * (1.0 + tax_factor)
end

#net(tax_factor) ⇒ Object



15
16
17
# File 'lib/slab/numeric.rb', line 15

def net(tax_factor)
  self / (1.0 + tax_factor)
end

#percentObject



6
7
8
# File 'lib/slab/numeric.rb', line 6

def percent
  self / 100.0
end

#sgnObject



31
32
33
34
35
36
37
38
39
# File 'lib/slab/numeric.rb', line 31

def sgn
  if self > 0
    1
  elsif self == 0
    0
  else
    -1
  end
end

#tax(factor) ⇒ Object



23
24
25
# File 'lib/slab/numeric.rb', line 23

def tax(factor)
  self * factor.to_f
end