Class: UnichronUtils::Quicktime

Inherits:
Object
  • Object
show all
Defined in:
lib/unichron.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time: Time.now, speed: 4) ⇒ Quicktime

Returns a new instance of Quicktime.



102
103
104
105
106
# File 'lib/unichron.rb', line 102

def initialize(time: Time.now, speed: 4)

  @time, @speed = Unichron.new(time).to_time, speed  

end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



100
101
102
# File 'lib/unichron.rb', line 100

def time
  @time
end

Instance Method Details

#pauseObject



123
124
125
# File 'lib/unichron.rb', line 123

def pause()
  @state = :pause
end

#playObject



127
128
129
# File 'lib/unichron.rb', line 127

def play()
  @state = :play
end

#set_time(s) ⇒ Object



131
132
133
# File 'lib/unichron.rb', line 131

def set_time(s)
  @time = Chronic.parse(s)
end

#startObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/unichron.rb', line 108

def start()

  @state = :play

  Thread.new do 

    loop do 
      (sleep 0.5; next) if @state == :pause
      @time += 1
      sleep 1.0 / @speed
    end

  end
end