Class: Mappum::RootMap

Inherits:
Map show all
Defined in:
lib/mappum/map.rb

Instance Attribute Summary collapse

Attributes inherited from Map

#bidi_maps, #maps, #source, #src_ref, #strip_empty

Instance Method Summary collapse

Methods inherited from Map

#strip_empty?

Constructor Details

#initialize(name) ⇒ RootMap

Returns a new instance of RootMap.



21
22
23
24
25
26
27
28
# File 'lib/mappum/map.rb', line 21

def initialize(name)
  super()
  @name = name
  @strip_empty = false
  @maps_by_name, @maps_by_from = {},{}
  @maps_by_from_to = {}
  @bidi_maps_by_name, @bidi_maps_by_class = {},{}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/mappum/map.rb', line 20

def name
  @name
end

Instance Method Details

#[](arg1, to_class = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/mappum/map.rb', line 29

def [](arg1, to_class=nil)
  from_class = arg1
  unless to_class.nil?
    key = [from_class.to_s, to_class.to_s]
    return @maps_by_from_to[key]
  end
  mpa = @maps_by_from[from_class.to_s]
  return mpa unless mpa.nil?
  return @maps_by_name[arg1.to_s]
end

#add(map) ⇒ Object

Add array of maps to catalogue. Makes name index for map search. Map names will be used and no 2 names can be the same in the catalogue/ Class names will be used for maps that are unique in regard to mapping from and to classes.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mappum/map.rb', line 62

def add(map)
  if map.normalized?
    raise "Duplicate map name #{map.name}" if @maps_by_name.include?(map.name)
    @maps_by_name[map.name] = map
    #When there are 2 maps from same class to other classes non will be found by default
    add_to_index(@maps_by_from, map.from.clazz.to_s, map)

    #When there are 2 maps from same class to same class non will be found by default
    from_to_key = [map.from.clazz.to_s, map.to.clazz.to_s]
    add_to_index(@maps_by_from_to, from_to_key, map)
  else
    raise "Duplicate map name #{map.name}" if @bidi_maps_by_name.include?(map.name)
    @bidi_maps_by_name[map.name] = map

    add_to_index(@bidi_maps_by_class, map.left.clazz.to_s, map)
    add_to_index(@bidi_maps_by_class, map.right.clazz.to_s, map)
  end
end

#get_bidi_map(name) ⇒ Object



39
40
41
42
43
44
# File 'lib/mappum/map.rb', line 39

def get_bidi_map(name)
  mpa = @bidi_maps_by_class[name.to_s]
  return mpa unless mpa.nil?
  
  return @bidi_maps_by_name[name.to_s]
end

#list_bidi_map_namesObject



51
52
53
54
55
# File 'lib/mappum/map.rb', line 51

def list_bidi_map_names
  list = []
  list += @bidi_maps_by_name.collect{|k, v| k}
  return list
end

#list_map_names(full_list = false) ⇒ Object



45
46
47
48
49
50
# File 'lib/mappum/map.rb', line 45

def list_map_names(full_list = false)
  list = []
  list += @maps_by_name.collect{|k,v| k}
  list += @maps_by_from.collect{|k,v| k} if full_list
  return list
end