Class: WebUnit::HtmlElem
Direct Known Subclasses
Form, Frame, Image, JSciriptOpenObject, Link, Param, SelectOption, Table, TableCell, TableRow
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #append(data) ⇒ Object
- #extract ⇒ Object
-
#find(tag) ⇒ Object
— HtmlElem#find(tag) return an Array of HtmlElems, which have ((|tag|)).
-
#has?(elem) ⇒ Boolean
— HtmlElem#has?(elem) return true, when self have ((|elem|)) as child.
-
#initialize(tag, ah = {}) ⇒ HtmlElem
constructor
A new instance of HtmlElem.
- #inspect ⇒ Object
-
#print(indent = '') ⇒ Object
— HtmlElem#print(indent=”) – FOR TEST USE ONLY print tree structure, from self to lower.
-
#readlink(str) ⇒ Object
— HtmlElem#readlink(str) return a Response, gotten with reading a Link have ((|str|)).
-
#search(data) ⇒ Object
— HtmlElem#search(data) return an Array of HtmlElems, which have ((|data|)).
Constructor Details
#initialize(tag, ah = {}) ⇒ HtmlElem
Returns a new instance of HtmlElem.
13 14 15 16 17 18 19 20 |
# File 'lib/webunit/htmlelem.rb', line 13 def initialize( tag, ah={} ) @children = [] @tag = tag @attrs = ah @data = '' @array = [] @name = ah['name'] if ah end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def array @array end |
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def attrs @attrs end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def children @children end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def name @name end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
11 12 13 |
# File 'lib/webunit/htmlelem.rb', line 11 def tag @tag end |
Instance Method Details
#append(data) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/webunit/htmlelem.rb', line 22 def append( data ) if data.is_a?( HtmlElem ) @children << data else @data << data end @array << data end |
#extract ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/webunit/htmlelem.rb', line 31 def extract data = '' @array.each do |e| if e.is_a?( String ) data << " #{e} " elsif e.is_a?( HtmlElem ) data << e.extract end end data.squeeze( ' ' ).strip end |
#find(tag) ⇒ Object
— HtmlElem#find(tag)
return an Array of HtmlElems, which have ((|tag|)).
55 56 57 58 59 60 61 62 |
# File 'lib/webunit/htmlelem.rb', line 55 def find( tag ) a = [] a.push self if @tag == tag @children.each do |c| a = a + c.find( tag ) end a end |
#has?(elem) ⇒ Boolean
— HtmlElem#has?(elem)
return true, when self have ((|elem|)) as child.
otherwise, return false.
((|elem|)) should be a HtmlElem or a String.
98 99 100 101 102 103 104 105 106 |
# File 'lib/webunit/htmlelem.rb', line 98 def has?( elem ) if elem.kind_of?( HtmlElem ) @children.include?( elem ) elsif elem.instance_of?( String ) @array.include?( elem ) else false end end |
#inspect ⇒ Object
43 44 45 46 47 48 |
# File 'lib/webunit/htmlelem.rb', line 43 def inspect return "<#toplevel>" if @tag == nil as = '' attrs.each{ |k,v| as << " #{k}=#{v}" } "<#{@tag+as}>:#{data}:" end |
#print(indent = '') ⇒ Object
— HtmlElem#print(indent=”) – FOR TEST USE ONLY
print tree structure, from self to lower.
113 114 115 116 117 118 |
# File 'lib/webunit/htmlelem.rb', line 113 def print( indent='' ) # not tested :-( puts indent + inspect @children.each do |c| c.print( indent + ' ' ) end end |
#readlink(str) ⇒ Object
— HtmlElem#readlink(str)
return a Response, gotten with reading a Link have ((|str|)).
raise ElemNotFound exception, when no Links found.
84 85 86 87 88 89 |
# File 'lib/webunit/htmlelem.rb', line 84 def readlink( str ) self.find( 'a' ).each do |link| return link.read if link.data == str end raise ElemNotFound, "no Links have '#{str}' as data." end |
#search(data) ⇒ Object
— HtmlElem#search(data)
return an Array of HtmlElems, which have ((|data|)).
69 70 71 72 73 74 75 76 |
# File 'lib/webunit/htmlelem.rb', line 69 def search( data ) a = [] a.push self if @data == data @children.each do |c| a = a + c.search( data ) end a end |