Sha256: feadc122d9f78b4c69fe49633b80ff6171de38d9ebaec7450b6e4b87aa45bbd3

Contents?: true

Size: 815 Bytes

Versions: 20

Compression:

Stored size: 815 Bytes

Contents

module Mittsu
  class Clock
    attr_accessor :auto_start, :start_time, :old_time, :elapsed_time, :running

    def initialize(auto_start = true)
      @auto_start = auto_start
      @start_time = 0
      @old_time = 0
      @elapsed_time = 0
      @running = false
    end

    def start
      @start_time = Time.now
      @old_time = @start_time
      @running = true
    end

    def stop
      self.get_elapsed_time
      @running = false
    end

    def get_elapsed_time
      self.get_delta
      @elapsed_time
    end

    def get_delta
      diff = 0
      if @auto_start && ! @running
        self.start
      end
      if @running
        new_time = Time.now
        diff = 0.001 * (new_time - @old_time)
        @old_time = new_time
        @elapsed_time += diff
      end
      diff
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mittsu-0.5.0 lib/mittsu/core/clock.rb
mittsu-0.4.1 lib/mittsu/core/clock.rb
mittsu-0.4.0 lib/mittsu/core/clock.rb
mittsu-0.3.3 lib/mittsu/core/clock.rb
mittsu-0.3.2 lib/mittsu/core/clock.rb
mittsu-0.3.1 lib/mittsu/core/clock.rb
mittsu-0.3.0 lib/mittsu/core/clock.rb
mittsu-0.2.4 lib/mittsu/core/clock.rb
mittsu-0.2.3 lib/mittsu/core/clock.rb
mittsu-0.2.2 lib/mittsu/core/clock.rb
mittsu-0.2.1 lib/mittsu/core/clock.rb
mittsu-0.2.0 lib/mittsu/core/clock.rb
mittsu-0.1.7 lib/mittsu/core/clock.rb
mittsu-0.1.6 lib/mittsu/core/clock.rb
mittsu-0.1.5 lib/mittsu/core/clock.rb
mittsu-0.1.4 lib/mittsu/core/clock.rb
mittsu-0.1.3 lib/mittsu/core/clock.rb
mittsu-0.1.2 lib/mittsu/core/clock.rb
mittsu-0.1.1 lib/mittsu/core/clock.rb
mittsu-0.1.0 lib/mittsu/core/clock.rb