class Insite::ComponentCollection
Attributes
args[R]
browser[R]
collection_member_type[R]
indentifiers[R]
query_scope[R]
site[R]
target[R]
Public Class Methods
collection?()
click to toggle source
Returns true if the class represents a collection, false if not. @return [true, false]
# File lib/insite/component/component_collection.rb, line 16 def self.collection? true end
new(query_scope, *args)
click to toggle source
# File lib/insite/component/component_collection.rb, line 45 def initialize(query_scope, *args) @site = query_scope.class.ancestors.include?(Insite) ? query_scope : query_scope.site @browser = @site.browser @collection_member_type = self.class.instance_variable_get(:@collection_member_type) @selector = @collection_member_type.selector if args[0].is_a?(Insite::Element) || args[0].is_a?(Watir::Element) @dom_type = nil @args = nil @target = args[0].target elsif args[0].is_a?(Insite::ElementCollection) || args[0].is_a?(Watir::ElementCollection) @dom_type = nil @args = nil @target = args[0] else @args = parse_args(args) @selector = @args @non_relative = @args.delete(:non_relative) || false if @non_relative @query_scope = query_scope.site else query_scope.respond_to?(:target) ? obj = query_scope : obj = query_scope.site @query_scope = obj end if watir_class = Insite::CLASS_MAP.key(self.class) @target = watir_class.new(@query_scope.target, @args) else @target = Watir::HTMLElementCollection.new(@query_scope.target, @args) end end end
Public Instance Methods
==(other)
click to toggle source
# File lib/insite/component/component_collection.rb, line 20 def ==(other) to_a == other.to_a end
Also aliased as: eql?
[](idx)
click to toggle source
# File lib/insite/component/component_collection.rb, line 25 def[](idx) to_a[idx] end
collection?()
click to toggle source
# File lib/insite/component/component_collection.rb, line 29 def collection? true end
each(&block)
click to toggle source
# File lib/insite/component/component_collection.rb, line 37 def each(&block) to_a.each(&block) end
empty?()
click to toggle source
# File lib/insite/component/component_collection.rb, line 41 def empty? length == 0 end
first()
click to toggle source
# File lib/insite/component/component_collection.rb, line 33 def first to_a[0] end
inspect()
click to toggle source
# File lib/insite/component/component_collection.rb, line 80 def inspect @selector.empty? ? s = '{element: (selenium element)}' : s = @selector.to_s "#<#{self.class}: @query_scope: #{@query_scope}; @selector=#{s}>" end
last()
click to toggle source
# File lib/insite/component/component_collection.rb, line 85 def last to_a[-1] end
length()
click to toggle source
# File lib/insite/component/component_collection.rb, line 89 def length to_a.length end
text()
click to toggle source
# File lib/insite/component/component_collection.rb, line 95 def text to_a.map(&:text) end
to_a()
click to toggle source
# File lib/insite/component/component_collection.rb, line 99 def to_a out = [] @target.to_a.each_with_index do |elem, idx| out << @collection_member_type.new( @query_scope, @args.merge!(index: idx) ) end out end