Class: GoobySaxPathParser

Inherits:
GoobyBaseSaxParser show all
Defined in:
lib/gooby_sax_path_parser.rb

Overview

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.


This class is used to explore the structure of large xml files which are too large and deep to visually comprehend, such Garmin xml/tcx files.

Instance Attribute Summary collapse

Attributes inherited from GoobyBaseSaxParser

#current_tagname, #end_reached, #error, #exception, #list, #mappings, #xml

Instance Method Summary collapse

Methods inherited from GoobyBaseSaxParser

#end_reached?, #get_current_text, #has_error?, #has_exception?, #initialize, #on_cdata_block, #on_characters, #on_end_document, #on_error, #process_file, #process_xml, #set_error

Constructor Details

This class inherits a constructor from GoobyBaseSaxParser

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



15
16
17
# File 'lib/gooby_sax_path_parser.rb', line 15

def counter
  @counter
end

Instance Method Details

#current_pathObject



32
33
34
# File 'lib/gooby_sax_path_parser.rb', line 32

def current_path
  @tags.join('|')
end

#display_structureObject



36
37
38
39
40
41
# File 'lib/gooby_sax_path_parser.rb', line 36

def display_structure
  @counter.sorted_keys.each { | key | 
    count = @counter.value(key)
    puts sprintf("%-9d %-100s", count, key)
  }
end

#on_end_element(name, prefix = nil, uri = nil) ⇒ Object



28
29
30
# File 'lib/gooby_sax_path_parser.rb', line 28

def on_end_element(name, prefix=nil, uri=nil)        
  @tags.pop   
end

#on_start_element(name, attributes, prefix = nil, uri = nil, namespaces = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/gooby_sax_path_parser.rb', line 21

def on_start_element(name, attributes, prefix=nil, uri=nil, namespaces=nil)
  @tags.push(name) 
  @counter.increment('on_start_element')
  @counter.increment(current_path)
  attributes.keys.each { | key | @counter.increment("#{current_path}@#{key}") }
end

#subclass_initializeObject



17
18
19
# File 'lib/gooby_sax_path_parser.rb', line 17

def subclass_initialize
  @tags, @mappings, @counter = [], {}, GoobyCounterHash.new
end