Class: Browser::Interval
Overview
Allows you to create an interval that executes the function every given seconds.
Instance Attribute Summary collapse
- 
  
    
      #every  ⇒ Float 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The seconds every which the block is called.
 
Instance Method Summary collapse
- 
  
    
      #abort  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Abort the interval, it won’t be possible to start it again.
 - 
  
    
      #aborted?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the interval has been aborted.
 - 
  
    
      #call  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Call the [Interval] block.
 - 
  
    
      #initialize(window, time, &block)  ⇒ Interval 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Create and start an interval.
 - 
  
    
      #start  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Start the interval if it has been stopped.
 - 
  
    
      #stop  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Stop the interval, it will be possible to start it again.
 - 
  
    
      #stopped?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the interval has been stopped.
 
Constructor Details
#initialize(window, time, &block) ⇒ Interval
Create and start an interval.
      16 17 18 19 20 21 22  | 
    
      # File 'lib/reactive_record/interval.rb', line 16 def initialize(window, time, &block) @window = Native.convert(window) @every = time @block = block @aborted = false end  | 
  
Instance Attribute Details
#every ⇒ Float (readonly)
Returns the seconds every which the block is called.
      10 11 12  | 
    
      # File 'lib/reactive_record/interval.rb', line 10 def every @every end  | 
  
Instance Method Details
#abort ⇒ Object
Abort the interval, it won’t be possible to start it again.
      35 36 37 38 39 40  | 
    
      # File 'lib/reactive_record/interval.rb', line 35 def abort `#@window.clearInterval(#@id)` @aborted = true @id = nil end  | 
  
#aborted? ⇒ Boolean
Check if the interval has been aborted.
      30 31 32  | 
    
      # File 'lib/reactive_record/interval.rb', line 30 def aborted? @aborted end  | 
  
#call ⇒ Object
Call the [Interval] block.
      61 62 63  | 
    
      # File 'lib/reactive_record/interval.rb', line 61 def call @block.call end  | 
  
#start ⇒ Object
Start the interval if it has been stopped.
      53 54 55 56 57 58  | 
    
      # File 'lib/reactive_record/interval.rb', line 53 def start raise "the interval has been aborted" if aborted? return unless stopped? @id = `#@window.setInterval(#@block, #@every * 1000)` end  | 
  
#stop ⇒ Object
Stop the interval, it will be possible to start it again.
      43 44 45 46 47 48 49 50  | 
    
      # File 'lib/reactive_record/interval.rb', line 43 def stop return if stopped? `#@window.clearInterval(#@id)` @stopped = true @id = nil end  | 
  
#stopped? ⇒ Boolean
Check if the interval has been stopped.
      25 26 27  | 
    
      # File 'lib/reactive_record/interval.rb', line 25 def stopped? @id.nil? end  |