Class: Dommy::TouchList

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

Overview

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

Constant Summary collapse

JS_METHOD_NAMES =

Methods routed through js_call (keep in sync with its when-arms).

%w[item].freeze

Instance Method Summary collapse

Constructor Details

#initialize(touches = []) ⇒ TouchList

Returns a new instance of TouchList.



631
632
633
# File 'lib/dommy/event.rb', line 631

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

Instance Method Details

#[](index) ⇒ Object



643
644
645
# File 'lib/dommy/event.rb', line 643

def [](index)
  item(index)
end

#__js_call__(method, args) ⇒ Object



667
668
669
670
671
672
# File 'lib/dommy/event.rb', line 667

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

#__js_get__(key) ⇒ Object



652
653
654
655
656
657
658
659
# File 'lib/dommy/event.rb', line 652

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

#__js_method_names__Object



663
664
665
# File 'lib/dommy/event.rb', line 663

def __js_method_names__
  JS_METHOD_NAMES
end

#each(&block) ⇒ Object



647
648
649
650
# File 'lib/dommy/event.rb', line 647

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

#item(index) ⇒ Object



639
640
641
# File 'lib/dommy/event.rb', line 639

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

#lengthObject



635
636
637
# File 'lib/dommy/event.rb', line 635

def length
  @touches.length
end