Class: MotionKit::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-kit/calculator/calculator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#constantObject

Returns the value of attribute constant.



4
5
6
# File 'lib/motion-kit/calculator/calculator.rb', line 4

def constant
  @constant
end

#factorObject

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

.memoObject



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