Class: MotionKit::Calculator
- Defined in:
- lib/motion-kit/calculator/calculator.rb
Instance Attribute Summary collapse
-
#constant ⇒ Object
Returns the value of attribute constant.
-
#factor ⇒ Object
Returns the value of attribute factor.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(amount) ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize(amount) ⇒ Calculator
Returns a new instance of Calculator.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/motion-kit/calculator/calculator.rb', line 15 def initialize(amount) location = amount.index '%' if location self.factor = amount.slice(0, location).to_f / 100.0 location += 1 else self.factor = 0 location = 0 end self.constant = amount.slice(location, amount.size).to_f end |
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant.
4 5 6 |
# File 'lib/motion-kit/calculator/calculator.rb', line 4 def constant @constant end |
#factor ⇒ Object
Returns the value of attribute factor.
4 5 6 |
# File 'lib/motion-kit/calculator/calculator.rb', line 4 def factor @factor end |
Class Method Details
.memo ⇒ Object
6 7 8 |
# File 'lib/motion-kit/calculator/calculator.rb', line 6 def self.memo @memo ||= {} end |
.scan(amount) ⇒ Object
10 11 12 13 |
# File 'lib/motion-kit/calculator/calculator.rb', line 10 def self.scan(amount) amount = amount.gsub(' ', '') Calculator.memo[amount] ||= Calculator.new(amount) end |