Class: Lipseys::Parser
- Inherits:
-
Object
- Object
- Lipseys::Parser
- Defined in:
- lib/lipseys/parser.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
- #parse(node_name, &block) ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
6 7 8 |
# File 'lib/lipseys/parser.rb', line 6 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/lipseys/parser.rb', line 4 def file @file end |
Class Method Details
.parse(file, node_name, &block) ⇒ Object
10 11 12 |
# File 'lib/lipseys/parser.rb', line 10 def self.parse(file, node_name, &block) new(file).parse(node_name, &block) end |
Instance Method Details
#parse(node_name, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/lipseys/parser.rb', line 14 def parse(node_name, &block) File.open(@file) do |file| Nokogiri::XML::Reader.from_io(file).each do |node| if node.name == node_name and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT yield(Nokogiri::XML(node.outer_xml)) end end end end |