Class: Insite::ComponentCollection

Inherits:
Object
  • Object
show all
Extended by:
ComponentMethods, DOMMethods
Includes:
Enumerable, CommonMethods, ComponentInstanceMethods, ElementInstanceMethods
Defined in:
lib/insite/component/component_collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementInstanceMethods

#a, #abbr, #abbrs, #address, #addresses, #area, #areas, #article, #articles, #as, #aside, #asides, #audio, #audios, #b, #base, #bases, #bdi, #bdis, #bdo, #bdos, #blockquote, #blockquotes, #body, #bodys, #br, #brs, #bs, #button, #buttons, #canvas, #canvases, #caption, #captions, #cell, #cells, #checkbox, #checkboxes, #circle, #circles, #cite, #cites, #code, #codes, #col, #colgroup, #colgroups, #cols, #data, #datalist, #datalists, #datas, #date_field, #date_fields, #date_time_field, #date_time_fields, #dd, #dds, #defs, #defss, #del, #dels, #desc, #descs, #details, #detailses, #dfn, #dfns, #div, #divs, #dl, #dls, #dt, #dts, #element, #elements, #ellipse, #ellipses, #em, #embed, #embeds, #ems, #field_set, #field_sets, #fieldset, #fieldsets, #figcaption, #figcaptions, #figure, #figures, #file_field, #file_fields, #font, #fonts, #footer, #footers, #foreign_object, #foreign_objects, #form, #forms, #frame, #frames, #frameset, #framesets, #g, #gs, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #head, #header, #headers, #heads, #hidden, #hiddens, #hr, #hrs, #htmls, #i, #iframe, #iframes, #image, #images, #img, #imgs, #input, #inputs, #ins, #inses, #is, #kbd, #kbds, #label, #labels, #legend, #legends, #li, #line, #linear_gradient, #linear_gradients, #lines, #link, #links, #lis, #main, #mains, #map, #maps, #mark, #marker, #markers, #marks, #meta, #metadata, #metadatas, #metas, #meter, #meters, #nav, #navs, #noscript, #noscripts, #object, #objects, #ol, #ols, #optgroup, #optgroups, #option, #options, #output, #outputs, #p, #param, #params, #path, #paths, #pattern, #patterns, #picture, #pictures, #polygon, #polygons, #polyline, #polylines, #pre, #pres, #progress, #progresses, #ps, #q, #qs, #radial_gradient, #radial_gradients, #radio, #radios, #rb, #rbs, #rect, #rects, #row, #rows, #rp, #rps, #rt, #rtc, #rtcs, #rts, #rubies, #ruby, #s, #samp, #samps, #script, #scripts, #section, #sections, #select, #select_list, #select_lists, #selects, #small, #smalls, #source, #sources, #span, #spans, #ss, #stop, #stops, #strong, #strongs, #style, #styles, #sub, #subs, #summaries, #summary, #sup, #sups, #svg, #svgs, #switch, #switches, #symbol, #symbols, #table, #tables, #tbody, #tbodys, #td, #tds, #template, #templates, #text_field, #text_fields, #text_path, #text_paths, #textarea, #textareas, #tfoot, #tfoots, #th, #thead, #theads, #ths, #time, #times, #titles, #tr, #track, #tracks, #trs, #tspan, #tspans, #u, #ul, #uls, #us, #use, #uses, #var, #vars, #video, #videos, #view, #views, #wbr, #wbrs

Methods included from CommonMethods

#document, #process_browser, #update_object

Constructor Details

#initialize(query_scope, *args) ⇒ ComponentCollection

Returns a new instance of ComponentCollection.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def args
  @args
end

#browserObject (readonly)

Returns the value of attribute browser.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def browser
  @browser
end

#collection_member_typeObject (readonly)

Returns the value of attribute collection_member_type.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def collection_member_type
  @collection_member_type
end

#indentifiersObject (readonly)

Returns the value of attribute indentifiers.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def indentifiers
  @indentifiers
end

#query_scopeObject (readonly)

Returns the value of attribute query_scope.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def query_scope
  @query_scope
end

#siteObject (readonly)

Returns the value of attribute site.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def site
  @site
end

#targetObject (readonly)

Returns the value of attribute target.



3
4
5
# File 'lib/insite/component/component_collection.rb', line 3

def target
  @target
end

Class Method Details

.collection?true, false

Returns true if the class represents a collection, false if not.

Returns:

  • (true, false)


16
17
18
# File 'lib/insite/component/component_collection.rb', line 16

def self.collection?
  true
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



20
21
22
# File 'lib/insite/component/component_collection.rb', line 20

def ==(other)
  to_a == other.to_a
end

#[](idx) ⇒ Object



25
26
27
# File 'lib/insite/component/component_collection.rb', line 25

def[](idx)
  to_a[idx]
end

#collection?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/insite/component/component_collection.rb', line 29

def collection?
  true
end

#each(&block) ⇒ Object



37
38
39
# File 'lib/insite/component/component_collection.rb', line 37

def each(&block)
  to_a.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/insite/component/component_collection.rb', line 41

def empty?
  length == 0
end

#firstObject



33
34
35
# File 'lib/insite/component/component_collection.rb', line 33

def first
  to_a[0]
end

#inspectObject



80
81
82
83
# 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

#lastObject



85
86
87
# File 'lib/insite/component/component_collection.rb', line 85

def last
  to_a[-1]
end

#lengthObject Also known as: count, size



89
90
91
# File 'lib/insite/component/component_collection.rb', line 89

def length
  to_a.length
end

#textObject



95
96
97
# File 'lib/insite/component/component_collection.rb', line 95

def text
  to_a.map(&:text)
end

#to_aObject



99
100
101
102
103
104
105
106
107
108
# 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