Sha256: 7cabd827293fa4c25a81b2bfde7790cfb1e4adcfc8a112eda64f35919cd51808

Contents?: true

Size: 592 Bytes

Versions: 24

Compression:

Stored size: 592 Bytes

Contents

# @provides MotionKit::Calculator
module MotionKit
  class Calculator
    attr_accessor :factor, :constant

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

    def self.scan(amount)
      amount = amount.gsub(' ', '')
      Calculator.memo[amount] ||= Calculator.new(amount)
    end

    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

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
motion-kit-0.10.9 lib/motion-kit/calculator/calculator.rb
motion-kit-0.10.8 lib/motion-kit/calculator/calculator.rb
motion-kit-0.10.7 lib/motion-kit/calculator/calculator.rb
motion-kit-0.10.6 lib/motion-kit/calculator/calculator.rb