Class: Parser::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/Parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attrObject (readonly)

Returns the value of attribute attr.



3
4
5
# File 'lib/Parser.rb', line 3

def attr
  @attr
end

#elementsObject (readonly)

Returns the value of attribute elements.



3
4
5
# File 'lib/Parser.rb', line 3

def elements
  @elements
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/Parser.rb', line 3

def name
  @name
end

#namespaceObject (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_sObject



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