File tree 2 files changed +2
-34
lines changed
2 files changed +2
-34
lines changed Original file line number Diff line number Diff line change @@ -247,45 +247,13 @@ def offset
247
247
Hash . from_native ( `#{ self } .offset()` )
248
248
end
249
249
250
- # Yields each element in #{self} collection in turn. The yielded element
251
- # is wrapped as a `DOM` instance.
252
- #
253
- # @example
254
- #
255
- # DOM('.foo').each { |e| puts "The element id: #{e.id}" }
256
- #
257
- # @return returns the receiver
258
250
def each
259
251
`for (var i = 0, length = #{ self } .length; i < length; i++) {`
260
252
yield `$(#{ self } [i])`
261
253
`}`
262
254
self
263
255
end
264
256
265
- # return an opal array mapped with block yielded for any element
266
- #
267
- # @example
268
- #
269
- # list = Document.find('table.players td.surname').map {|el| el.html }
270
- #
271
- # @return an Array
272
- def map
273
- list = [ ]
274
- each { |el | list << yield ( el ) }
275
- list
276
- end
277
-
278
- # return an opal Array of elements
279
- #
280
- # @example
281
- #
282
- # Document.find('table.players td.surname').to_a.last
283
- #
284
- # @return an Array
285
- def to_a
286
- map { |el | el }
287
- end
288
-
289
257
def first
290
258
`#{ self } .length ? #{ self } .first() : nil`
291
259
end
Original file line number Diff line number Diff line change 37
37
it "should return a list of class Array" do
38
38
Element . find ( 'table.players td.surname' ) . to_a . class . should == Array
39
39
end
40
-
40
+
41
41
it "should check first and last element" do
42
42
Element . find ( 'table.players td.surname' ) . to_a . first . html == "rossi"
43
43
Element . find ( 'table.players td.surname' ) . to_a . last . html == "bianchi"
44
44
end
45
-
45
+
46
46
it "should get only element with class surname" do
47
47
Element . find ( 'table.players td' ) . to_a . select { |el | el . has_class? ( 'surname' ) } .
48
48
map { |el | el . class } . uniq == [ 'surname' ]
You can’t perform that action at this time.
0 commit comments