Class: HTMLParser::Tag
- Inherits:
-
Object
- Object
- HTMLParser::Tag
- Defined in:
- lib/html-renderer/html_parser.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, attrs = {}, children = []) ⇒ Tag
constructor
A new instance of Tag.
- #recursive_inspect(depth = 0) ⇒ Object
Constructor Details
#initialize(name, attrs = {}, children = []) ⇒ Tag
Returns a new instance of Tag.
36 37 38 39 40 |
# File 'lib/html-renderer/html_parser.rb', line 36 def initialize(name, attrs={}, children=[]) @name = name @attrs = attrs @children = children end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
23 24 25 |
# File 'lib/html-renderer/html_parser.rb', line 23 def attrs @attrs end |
#children ⇒ Object
Returns the value of attribute children.
23 24 25 |
# File 'lib/html-renderer/html_parser.rb', line 23 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/html-renderer/html_parser.rb', line 23 def name @name end |
Class Method Details
.from_str(s) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/html-renderer/html_parser.rb', line 25 def self.from_str(s) name, rest = s.split(/\s+/, 2) if rest attrs = rest.scan(HTMLParser::ATTR_RE).flatten.compact.each_slice(2).to_h else attrs = {} end new(name, attrs) end |
Instance Method Details
#recursive_inspect(depth = 0) ⇒ Object
42 43 44 45 46 |
# File 'lib/html-renderer/html_parser.rb', line 42 def recursive_inspect(depth=0) curdent = " "*depth indent = " "*(depth+1) "#{curdent}<#{name} #{attrs}>\n#{indent}#{children.map{|c| c.recursive_inspect(depth+1)}}\n#{curdent}</#{name}>" end |