Module: WannaBeParser::ClassMethods

Defined in:
lib/wannabeparser.rb

Instance Method Summary collapse

Instance Method Details

#element(o) ⇒ Object



18
19
20
# File 'lib/wannabeparser.rb', line 18

def element(o)
	@elements.merge!(o)
end

#elementsObject



22
23
24
# File 'lib/wannabeparser.rb', line 22

def elements
	@elements ||= {}
end

#parse(filepath) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wannabeparser.rb', line 30

def parse(filepath)
	@counter = 0
	@flow = LibXML::XML::Reader.document(document(filepath))

	raise 'I/O error or no such file' if @flow.nil?

	while @flow.read do
		parse_tag(@flow.expand) if @flow.node_type == LibXML::XML::Reader::TYPE_ELEMENT && @flow.name == @tag
	end

	@counter
end

#process(func) ⇒ Object



26
27
28
# File 'lib/wannabeparser.rb', line 26

def process(func)
	@process = func
end

#tag(tag) ⇒ Object



14
15
16
# File 'lib/wannabeparser.rb', line 14

def tag(tag)
	@tag = tag
end