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-1.1.1 lib/motion-kit/calculator/calculator.rb
motion-kit-1.1.0 lib/motion-kit/calculator/calculator.rb
motion-kit-1.0.3 lib/motion-kit/calculator/calculator.rb
motion-kit-1.0.2 lib/motion-kit/calculator/calculator.rb
motion-kit-1.0.1 lib/motion-kit/calculator/calculator.rb
motion-kit-1.0.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.18.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.17.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.16.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.15.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.14.2 lib/motion-kit/calculator/calculator.rb
motion-kit-0.14.1 lib/motion-kit/calculator/calculator.rb
motion-kit-0.14.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.13.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.12.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.11.2 lib/motion-kit/calculator/calculator.rb
motion-kit-0.11.1 lib/motion-kit/calculator/calculator.rb
motion-kit-0.11.0 lib/motion-kit/calculator/calculator.rb
motion-kit-0.10.11 lib/motion-kit/calculator/calculator.rb
motion-kit-0.10.10 lib/motion-kit/calculator/calculator.rb