Module: Slab::NumericExt
- Defined in:
- lib/slab/numeric.rb
Defined Under Namespace
Classes: DiscountTooBig
Instance Method Summary collapse
- #commercial_round ⇒ Object
- #discount(factor) ⇒ Object
- #gross(tax_factor) ⇒ Object
- #net(tax_factor) ⇒ Object
- #percent ⇒ Object
- #sgn ⇒ Object
- #tax(factor) ⇒ Object
Instance Method Details
#commercial_round ⇒ Object
27 28 29 |
# File 'lib/slab/numeric.rb', line 27 def commercial_round (self * 100.0).round / 100.0 end |
#discount(factor) ⇒ Object
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 |
#percent ⇒ Object
6 7 8 |
# File 'lib/slab/numeric.rb', line 6 def percent self / 100.0 end |
#sgn ⇒ Object
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 |