Class: XMLFormat::Listener
- Inherits:
-
Object
- Object
- XMLFormat::Listener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/thinp_xml/thinp/xml_format.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #get_fields(attr, flds) ⇒ Object
-
#initialize ⇒ Listener
constructor
A new instance of Listener.
- #tag_end(tag) ⇒ Object
- #tag_start(tag, args) ⇒ Object
- #text(data) ⇒ Object
- #to_hash(pairs) ⇒ Object
Constructor Details
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
43 44 45 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 43 def @metadata end |
Instance Method Details
#get_fields(attr, flds) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 57 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) ⇒ Object
98 99 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 98 def tag_end(tag) end |
#tag_start(tag, args) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 75 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) ⇒ Object
101 102 103 104 105 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 101 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
49 50 51 52 53 54 55 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 49 def to_hash(pairs) r = Hash.new pairs.each do |p| r[p[0].intern] = p[1] end r end |