Class: AePageObjects::Collection

Inherits:
Element show all
Defined in:
lib/ae_page_objects/elements/collection.rb

Constant Summary

Constants included from Node::Methods

Node::Methods::METHODS_TO_DELEGATE_TO_NODE

Class Attribute Summary collapse

Attributes inherited from Element

#parent

Instance Method Summary collapse

Methods inherited from Element

#__full_name__, #__name__, #document, #full_name, #initialize, #name, new, #to_s, #using_default_locator?

Methods included from Dsl

#collection, #element, #form_for, #inherited

Methods included from InternalHelpers

#ensure_class_for_param!

Methods included from Node::ClassMethods

#current_url, #current_url_without_params, #new_subclass

Methods included from AePageObjects::Concerns::Staleable

#node, #stale?

Methods included from AePageObjects::Concerns::LoadEnsuring

#initialize

Methods included from Node::Methods

#current_url, #current_url_without_params, #document, #initialize, #node

Constructor Details

This class inherits a constructor from AePageObjects::Element

Class Attribute Details

.item_classObject

Returns the value of attribute item_class.



4
5
6
# File 'lib/ae_page_objects/elements/collection.rb', line 4

def item_class
  @item_class
end

Instance Method Details

#[](index, &block) ⇒ Object



26
27
28
# File 'lib/ae_page_objects/elements/collection.rb', line 26

def [](index, &block)
  at(index, &block)
end

#add_more(&block) ⇒ Object



54
55
56
57
# File 'lib/ae_page_objects/elements/collection.rb', line 54

def add_more(&block)
  append
  last(&block)
end

#allObject



36
37
38
39
40
# File 'lib/ae_page_objects/elements/collection.rb', line 36

def all
  [].tap do |all|
    self.each { |item| all << item }
  end
end

#at(index, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ae_page_objects/elements/collection.rb', line 18

def at(index, &block)
  if index >= size || index < 0
    nil
  else
    self.item_class.new(self, :name => index, :locator => [:xpath, "#{row_xpath}[#{index + 1}]"], &block)
  end
end

#each(&block) ⇒ Object



30
31
32
33
34
# File 'lib/ae_page_objects/elements/collection.rb', line 30

def each(&block)
  (0..(size - 1)).each do |index|
    yield at(index)
  end
end

#first(&block) ⇒ Object



46
47
48
# File 'lib/ae_page_objects/elements/collection.rb', line 46

def first(&block)
  self.at(0, &block)
end

#item_classObject



14
15
16
# File 'lib/ae_page_objects/elements/collection.rb', line 14

def item_class
  self.class.item_class
end

#last(&block) ⇒ Object



50
51
52
# File 'lib/ae_page_objects/elements/collection.rb', line 50

def last(&block)
  self.at(size - 1, &block)
end

#row_xpathObject



59
60
61
# File 'lib/ae_page_objects/elements/collection.rb', line 59

def row_xpath
  @row_xpath || ".//*[contains(@class, 'item-list')]//*[contains(@class,'row') and not(contains(@style,'display'))]"
end

#sizeObject



42
43
44
# File 'lib/ae_page_objects/elements/collection.rb', line 42

def size
  node.all(:xpath, row_xpath).size
end