Class: InOurTime::Tic
- Inherits:
-
Object
- Object
- InOurTime::Tic
- Defined in:
- lib/iot/iot.rb
Instance Method Summary collapse
- #ended ⇒ Object
- #inc_processes ⇒ Object
- #init_processes ⇒ Object
-
#initialize ⇒ Tic
constructor
A new instance of Tic.
- #kill ⇒ Object
- #playing_time ⇒ Object
- #process ⇒ Object
- #run ⇒ Object
- #timeout?(type) ⇒ Boolean
- #toc ⇒ Object
Constructor Details
#initialize ⇒ Tic
Returns a new instance of Tic.
28 29 30 31 32 33 |
# File 'lib/iot/iot.rb', line 28 def initialize Thread.abort_on_exception = true @flag = false init_processes run end |
Instance Method Details
#ended ⇒ Object
72 73 74 |
# File 'lib/iot/iot.rb', line 72 def ended timeout? :ended end |
#inc_processes ⇒ Object
49 50 51 |
# File 'lib/iot/iot.rb', line 49 def inc_processes @processes.each { |process| process[:value] += 1 } end |
#init_processes ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/iot/iot.rb', line 35 def init_processes @processes = { process: { timeout: 5, value: 0 }, playing_time: { timeout: 1, value: 0 }, ended: { timeout: 1, value: 0 } } end |
#kill ⇒ Object
53 54 55 |
# File 'lib/iot/iot.rb', line 53 def kill Thread.kill(@th_tic) if @th_tic end |
#playing_time ⇒ Object
68 69 70 |
# File 'lib/iot/iot.rb', line 68 def timeout? :playing_time end |
#process ⇒ Object
64 65 66 |
# File 'lib/iot/iot.rb', line 64 def process timeout? :process end |
#run ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/iot/iot.rb', line 76 def run Thread.abort_on_exception = true @th_tic = Thread.new do loop do sleep 0.2 @processes[:process][:value] += 1 @processes[:playing_time][:value] += 1 @processes[:ended][:value] += 1 @flag = true end end end |
#timeout?(type) ⇒ Boolean
57 58 59 60 61 62 |
# File 'lib/iot/iot.rb', line 57 def timeout? type @processes[type] return unless @processes[type][:value] > @processes[type][:timeout] @processes[type][:value] = 0 true end |
#toc ⇒ Object
89 90 91 92 93 |
# File 'lib/iot/iot.rb', line 89 def toc ret_val = @flag @flag = false ret_val end |