Class: MotionKit::Calculator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#constantObject

Returns the value of attribute constant.



235
236
237
# File 'lib/motion-kit/calculate.rb', line 235

def constant
  @constant
end

#factorObject

Returns the value of attribute factor.



235
236
237
# File 'lib/motion-kit/calculate.rb', line 235

def factor
  @factor
end

Class Method Details

.memoObject



237
238
239
# File 'lib/motion-kit/calculate.rb', line 237

def self.memo
  @memo ||= {}
end

.scan(amount) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/motion-kit/calculate.rb', line 241

def self.scan(amount)
  amount = amount.gsub(' ', '')
  return Calculator.memo[amount] if Calculator.memo[amount]

  calc = Calculator.new

  location = amount.index '%'
  if location
    calc.factor = amount.slice(0, location).to_f / 100.0
    location += 1
  else
    calc.factor = 0
    location = 0
  end
  calc.constant = amount.slice(location, amount.size).to_f

  Calculator.memo[amount] = calc
  return calc
end