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.



1192
1193
1194
# File 'lib/dommy/event.rb', line 1192

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

Instance Method Details

#[](index) ⇒ Object



1204
1205
1206
# File 'lib/dommy/event.rb', line 1204

def [](index)
  item(index)
end

#__js_call__(method, args) ⇒ Object



1224
1225
1226
1227
1228
1229
# File 'lib/dommy/event.rb', line 1224

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

#__js_get__(key) ⇒ Object



1213
1214
1215
1216
1217
1218
1219
1220
# File 'lib/dommy/event.rb', line 1213

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



1208
1209
1210
1211
# File 'lib/dommy/event.rb', line 1208

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

#item(index) ⇒ Object



1200
1201
1202
# File 'lib/dommy/event.rb', line 1200

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

#lengthObject



1196
1197
1198
# File 'lib/dommy/event.rb', line 1196

def length
  @touches.length
end