class XMLFormat::Listener

Attributes

metadata[R]

Public Class Methods

new() click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 47
def initialize
  @metadata = Metadata.new(nil, Array.new)
end

Public Instance Methods

get_fields(attr, flds) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 59
def get_fields(attr, flds)
  flds.map do |n,t|
    case t
    when :int
      attr[n].to_i

    when :string
      attr[n]

    when :object
      attr[n]

    else
      raise "unknown field type"
    end
  end
end
tag_end(tag) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 100
def tag_end(tag)
end
tag_start(tag, args) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 77
def tag_start(tag, args)
  attr = to_hash(args)

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

  when 'device'
    attr[:mappings] = Array.new
    @current_device = Device.new(*get_fields(attr, DEVICE_FIELDS))
    @metadata.devices << @current_device

  when 'single_mapping'
    @current_device.mappings << Mapping.new(attr[:origin_block].to_i, attr[:data_block].to_i, 1, attr[:time])

  when 'range_mapping'
    @current_device.mappings << Mapping.new(*get_fields(attr, MAPPING_FIELDS))

  else
    puts "unhandled tag '#{tag} #{attr.map {|x| x.inspect}.join(', ')}'"
  end
end
text(data) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 103
def text(data)
  return if data =~ /^\w*$/ # ignore whitespace
  abbrev = data[0..40] + (data.length > 40 ? "..." : "")
  puts "  text    :    #{abbrev.inspect}"
end
to_hash(pairs) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 51
def to_hash(pairs)
  r = Hash.new
  pairs.each do |p|
    r[p[0].intern] = p[1]
  end
  r
end