Class: HtmlGen::Parser
- Inherits:
-
Object
- Object
- HtmlGen::Parser
- Defined in:
- lib/html_gen/parser.rb
Overview
A simple, lightweight and pure-Ruby class for parsing HTML-strings into elements.
Examples
doc = HtmlGen::Parser.new(str: a_html_variable)
html_ele = doc.eles.first
html_ele.name #=> "html"
Instance Attribute Summary collapse
-
#eles ⇒ Object
readonly
An array that holds all the parsed root-elements.
Instance Method Summary collapse
-
#initialize(args) ⇒ Parser
constructor
The constructor.
Constructor Details
#initialize(args) ⇒ Parser
The constructor. See class documentation for usage of this.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/html_gen/parser.rb', line 11 def initialize(args) if args[:io] @io = args[:io] elsif args[:str] @io = ::StringIO.new(args[:str]) else raise "Dont know how to handle given arguments." end raise "No ':io' was given." unless @io @eof = false @buffer = "" @eles = [] @eles_t = [] @debug = args[:debug] parse_tag while !@eof || !@buffer.empty? end |
Instance Attribute Details
#eles ⇒ Object (readonly)
An array that holds all the parsed root-elements.
8 9 10 |
# File 'lib/html_gen/parser.rb', line 8 def eles @eles end |