Module: ATSPI::Collection
- Includes:
- Enumerable
- Included in:
- SelectableCollection, SelectableCollection::Selected
- Defined in:
- lib/atspi/collection.rb
Overview
Included in classes representing a collection that can be iterated over. A Collection is an Enumerable adjusted to the what we can efficiently get from libatspi. In particular, it provides access to items by index and from the end of the collection.
Enumerable interface collapse
-
#[](idx) ⇒ Object
alias for #at.
-
#at(idx) ⇒ Object
Item at index
idx
. -
#count ⇒ 0
Default size of collection.
-
#each ⇒ Object
prerequisite for Enumerable.
-
#last(n = 1) ⇒ Object+
Item(s) from the end.
-
#length ⇒ Object
alias for #count.
-
#size ⇒ Object
alias for #count.
Representation collapse
-
#inspect ⇒ String
Instance as inspectable string.
Instance Method Details
#[](idx) ⇒ Object
alias for #at
29 30 31 |
# File 'lib/atspi/collection.rb', line 29 def [](idx) at(idx) end |
#at(idx) ⇒ Object
Returns item at index idx
.
18 19 20 21 22 23 24 25 26 |
# File 'lib/atspi/collection.rb', line 18 def at(idx) if idx.between?(0, count-1) yield idx elsif idx.between?(-count, -1) yield count+idx else nil end end |
#count ⇒ 0
Returns default size of collection.
34 35 36 |
# File 'lib/atspi/collection.rb', line 34 def count 0 end |
#each ⇒ Object
prerequisite for Enumerable
10 11 12 13 14 |
# File 'lib/atspi/collection.rb', line 10 def each count.times.each do |idx| yield at(idx) end end |
#inspect ⇒ String
Returns instance as inspectable string.
55 56 57 |
# File 'lib/atspi/collection.rb', line 55 def inspect "#<#{self.class.name}:0x#{'%x14' % __id__} @count=#{count}>" end |
#last(n = 1) ⇒ Object+
Returns item(s) from the end.
44 45 46 47 48 49 50 |
# File 'lib/atspi/collection.rb', line 44 def last(n = 1) if n > 1 [n,count].min.downto(1).map{ |idx| at(-idx) } else at(-1) end end |
#length ⇒ Object
alias for #count
40 |
# File 'lib/atspi/collection.rb', line 40 def length; count end |