Module: ThinpXML::Base::ListenerUtils

Included in:
CacheXML::CacheParseDetail::Listener, ParseDetail::Listener
Defined in:
lib/thinp_xml/listener.rb

Instance Method Summary collapse

Instance Method Details

#get_fields(attr, flds) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/thinp_xml/listener.rb', line 14

def get_fields(attr, flds)
  flds.map do |n,t|
    case t
    when :int
      attr[n].to_i

    when :bool
      case attr[n]
      when 'true'
        true
      when 'false'
        false
      else
        raise "bad boolean value '#{attr[n]}'"
      end

    when :string
      attr[n]

    when :object
      attr[n]

    else
      raise "unknown field type"
    end
  end
end

#text(data) ⇒ Object



42
43
44
45
46
# File 'lib/thinp_xml/listener.rb', line 42

def text(data)
  return if data =~ /^\w*$/ # ignore whitespace
  abbrev = data[0..40] + (data.length > 40 ? "..." : "")
  puts "  text    :    #{abbrev.inspect}"
end

#to_hash(pairs) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/thinp_xml/listener.rb', line 6

def to_hash(pairs)
  r = Hash.new
  pairs.each do |p|
    r[p[0].intern] = p[1]
  end
  r
end