Class: CacheXML::CacheParseDetail::Listener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener, ThinpXML::Base::ListenerUtils
Defined in:
lib/thinp_xml/cache/parse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ThinpXML::Base::ListenerUtils

#get_fields, #text, #to_hash

Constructor Details

#initializeListener

Returns a new instance of Listener.



17
18
19
20
21
# File 'lib/thinp_xml/cache/parse.rb', line 17

def initialize
  @metadata = Metadata.new(nil, [], [])
  @in_mappings = false
  @in_hints = false
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



15
16
17
# File 'lib/thinp_xml/cache/parse.rb', line 15

def 
  @metadata
end

Instance Method Details

#tag_end(tag) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/thinp_xml/cache/parse.rb', line 51

def tag_end(tag)
  case tag
  when 'mappings'
    @in_mappings = false

  when 'hints'
    @in_hints = false
  end
end

#tag_start(tag, args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/thinp_xml/cache/parse.rb', line 23

def tag_start(tag, args)
  attr = to_hash(args)

  case tag
  when 'superblock'
    @metadata.superblock = Superblock.new(*get_fields(attr, SUPERBLOCK_FIELDS))

  when 'mappings'
    @in_mappings = true

  when 'mapping'
    raise "not in mappings section" unless @in_mappings
    m = Mapping.new(*get_fields(attr, MAPPING_FIELDS))
    @metadata.mappings << m

  when 'hints'
    @in_hints = true

  when 'hint'
    raise "not in hints section" unless @in_hints
    h = Hint.new(*get_fields(attr, HINT_FIELDS))
    @metadata.hints << h

  else
    raise "unhandled tag '#{tag} #{attr.map {|x| x.inspect}.join(' ')}'"
  end
end