Class: GuindillaGUI::Timer
- Defined in:
- lib/guindilla_gui/guindilla_classes.rb
Overview
—————————————————————————-#
Timer #
—————————————————————————-#
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#secs ⇒ Object
readonly
Returns the value of attribute secs.
Attributes inherited from Guindilla
#active_id, #blocks, #elements, #inputs, #socket
Instance Method Summary collapse
-
#initialize(type, seconds, &block) ⇒ Timer
constructor
A new instance of Timer.
- #start ⇒ Object
- #stop ⇒ Object
- #toggle ⇒ Object
Methods inherited from Guindilla
#after, #alert, #align, #append, #attributes, #audio_out, #background, #border, #border_color, #border_radius, #border_width, #bullet_list, #button, #canvas, #chart, #checkbox, #circle, #color, #color_input, #container, #display, #every, #file_input, #font, #font_family, #font_size, #h_box, #h_rule, #heading, #height, #hide, #image, #justify, #line_break, #link, #margin, #move_to, #number_input, #on_click, #on_hover, #on_leave, #on_mouse_move, #opacity, #ordered_list, #padding, #para, #polygon, #radio_button, #range_slider, #rectangle, #rotate, #show, #size, #source, #square, #style, #sub_script, #sup_script, #text, #text_align, #text_input, #transition, #triangle, #url_input, #v_box, #video_out, #web_frame, #width
Constructor Details
#initialize(type, seconds, &block) ⇒ Timer
Returns a new instance of Timer.
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 567 def initialize(type, seconds, &block) @id = "timer_#{Time.now.hash.to_s.gsub('-', 'x')}" @secs = seconds @@gui.blocks[:"#{@id}"] = block if block_given? if type == "interval" send_js(%Q~ let #{@id} = setInterval(function(){ socket.send("#{@id}:!!:"); }, #{@secs * 1000}); ~) elsif type == "timeout" send_js(%Q~ let #{@id} = setTimeout(function(){ socket.send("#{@id}:!!:"); }, #{@secs * 1000}); ~) end @running = true end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
565 566 567 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 565 def id @id end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
565 566 567 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 565 def running @running end |
#secs ⇒ Object (readonly)
Returns the value of attribute secs.
565 566 567 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 565 def secs @secs end |
Instance Method Details
#start ⇒ Object
588 589 590 591 592 593 594 595 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 588 def start send_js(%Q~ #{@id} = setInterval(function(){ socket.send("#{@id}:!!:"); }, #{@secs * 1000}); ~) @running = true end |
#stop ⇒ Object
597 598 599 600 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 597 def stop send_js(%Q~ clearInterval(#{self.id}) ~) @running = false end |
#toggle ⇒ Object
602 603 604 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 602 def toggle self.running ? self.stop : self.start end |