class Mexico::FileSystem::FiestaMap

This class models a data container for map (or attribute value) structures.

Attributes

map_items[R]

Public Class Methods

from_xml(node) click to toggle source

Auxiliary method that reads a FiestaMap object from the standard XML representation of FiESTA. @param node [XML::Node] The XML node to read from @return [FiestaMap] The map object represented in that XML node.

# File lib/mexico/file_system/fiesta_map.rb, line 74
def self.from_xml(node)
  #puts "SOMEONE CALLED FiestaMap.from_xml"
  #puts node.name
  # @map = Hash.new

  map = self.new

  node.xpath('./MapItem').each do |mi|
    #puts mi.name
    #puts mi['key']
    #puts mi.text
    map[mi['key']]=mi.text
  end
  #puts map.size
  map
end
new(initial_vals={}) click to toggle source

Creates a new map instance. If initial_vals is defined and contains values, those will be used to populate the map. @param initial_vals [Hash] Initial values for the new map object.

# File lib/mexico/file_system/fiesta_map.rb, line 30
def initialize(initial_vals={})
  @map = Hash.new
  @map.merge!(initial_vals)
end

Public Instance Methods

[](k) click to toggle source

Retrieves the value for the given key k from the map. @param k [Object] The key to be used. @return [Object,nil] The corresponding value object, or nil

if there was no entry for the given key.
# File lib/mexico/file_system/fiesta_map.rb, line 47
def [](k)
  @map[k]
end
[]=(k,v) click to toggle source

Adds or modifies an entry with the key k in the map. @param k [Object] The key to be used. @param v [Object] The value to be used. @return [void]

# File lib/mexico/file_system/fiesta_map.rb, line 39
def []=(k,v)
  @map[k]=v
end
empty?() click to toggle source

Returns true iff this map is empty. @return [Boolean] Returns true iff this map is empty, false otherwise.

# File lib/mexico/file_system/fiesta_map.rb, line 59
def empty?
  @map.empty?
end
has_key?(k) click to toggle source

Returns true iff this map contains an entry with the given key. @param k [Object] The key to be found. @return [Boolean] Returns true iff the given key is used in this map, false otherwise.

# File lib/mexico/file_system/fiesta_map.rb, line 66
def has_key?(k)
  @map.has_key?(k)
end
size() click to toggle source

Returns the number of entries in this map. @return [Integer] The number of entries.

# File lib/mexico/file_system/fiesta_map.rb, line 53
def size
  @map.size
end
to_s() click to toggle source

Creates a human-readable string representation of this map. @return [String] A string describing this map object.

# File lib/mexico/file_system/fiesta_map.rb, line 93
def to_s
  @map.to_a.collect{|k,v| "#{k} => #{v}"}.join(", ")
end
to_xml(x) click to toggle source

Converts this map object to its standard XML representation @todo what does the variable x do? @return [XML::Node] the node containing the XML representation

# File lib/mexico/file_system/fiesta_map.rb, line 100
def to_xml(x)
  n = XML::new_node("Map")
  @map.each_pair do |k,v|
    i_node = XML::new_node("MapItem")
    i_node['key'] = k
    i_node.content = v
    n.add_child(i_node)
  end

  n
end