Class: Dommy::TouchList

Inherits:
Object
  • Object
show all
Includes:
Bridge::Methods, Enumerable
Defined in:
lib/dommy/event.rb

Overview

‘TouchList` — immutable, indexed collection of Touch points.

Instance Method Summary collapse

Methods included from Bridge::Methods

included

Constructor Details

#initialize(touches = []) ⇒ TouchList

Returns a new instance of TouchList.



782
783
784
# File 'lib/dommy/event.rb', line 782

def initialize(touches = [])
  @touches = touches.to_a.freeze
end

Instance Method Details

#[](index) ⇒ Object



794
795
796
# File 'lib/dommy/event.rb', line 794

def [](index)
  item(index)
end

#__js_call__(method, args) ⇒ Object



814
815
816
817
818
819
# File 'lib/dommy/event.rb', line 814

def __js_call__(method, args)
  case method
  when "item"
    item(args[0])
  end
end

#__js_get__(key) ⇒ Object



803
804
805
806
807
808
809
810
# File 'lib/dommy/event.rb', line 803

def __js_get__(key)
  case key
  when "length"
    length
  else
    item(key.to_i) if key.is_a?(Integer) || key.to_s.match?(/\A-?\d+\z/)
  end
end

#each(&block) ⇒ Object



798
799
800
801
# File 'lib/dommy/event.rb', line 798

def each(&block)
  @touches.each(&block)
  self
end

#item(index) ⇒ Object



790
791
792
# File 'lib/dommy/event.rb', line 790

def item(index)
  @touches[index.to_i]
end

#lengthObject



786
787
788
# File 'lib/dommy/event.rb', line 786

def length
  @touches.length
end