Class: Parser::Element
- Inherits:
-
Object
- Object
- Parser::Element
- Defined in:
- lib/Parser.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_element(&block) ⇒ Object
- #each_text(&block) ⇒ Object
-
#initialize(ns, n) ⇒ Element
constructor
A new instance of Element.
- #to_s ⇒ Object
Constructor Details
#initialize(ns, n) ⇒ Element
Returns a new instance of Element.
14 15 16 17 18 19 |
# File 'lib/Parser.rb', line 14 def initialize(ns, n) @namespace = ns.to_s @name = n.to_s @attr = Hash.new @elements = Array.new end |
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
3 4 5 |
# File 'lib/Parser.rb', line 3 def attr @attr end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
3 4 5 |
# File 'lib/Parser.rb', line 3 def elements @elements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/Parser.rb', line 3 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/Parser.rb', line 3 def namespace @namespace end |
Instance Method Details
#each(&block) ⇒ Object
5 6 7 |
# File 'lib/Parser.rb', line 5 def each(&block) @elements.each(&block) end |
#each_element(&block) ⇒ Object
8 9 10 |
# File 'lib/Parser.rb', line 8 def each_element(&block) each{|c| block.call(c) unless c.is_a?(String) } end |
#each_text(&block) ⇒ Object
11 12 13 |
# File 'lib/Parser.rb', line 11 def each_text(&block) each{|c| block.call(c) if c.is_a?(String) } end |
#to_s ⇒ Object
21 22 23 24 25 |
# File 'lib/Parser.rb', line 21 def to_s "<#{@namespace}:#{@name} #{@attr.map{|k,v| "#{k}=\"#{v}\"" }.join(" ")}>\n" + "#{@elements.join("\n")}\n" + "</#{@namespace}:#{@name}>" end |