Class: Mappum::RootMap

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

Instance Attribute Summary collapse

Attributes inherited from Map

#bidi_maps, #maps, #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
# File 'lib/mappum/map.rb', line 21

def initialize(name)
  super()
  @name = name
  @strip_empty = false
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

#[](clazz) ⇒ Object



26
27
28
29
30
31
# File 'lib/mappum/map.rb', line 26

def [](clazz)
  #TODO optimize
  mpa = @maps.find{|m| m.from.clazz == clazz or m.from.clazz.to_s == clazz.to_s }
  return mpa unless mpa.nil?
  return @maps.find{|m| "#{m.from.clazz}-to-#{m.to.clazz}" == clazz.to_s}
end

#get_bidi_map(name) ⇒ Object



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

def get_bidi_map(name)
  #TODO optimize
  mpa = @bidi_maps.find{|m| m.right.clazz == name or m.right.clazz.to_s == name.to_s }
  mpa ||= @bidi_maps.find{|m| m.left.clazz == name or m.left.clazz.to_s == name.to_s }
  return mpa unless mpa.nil?
  
  return @bidi_maps.find{|m| "#{m.left.clazz}-to-from-#{m.right.clazz}" == name.to_s}
end

#list_bidi_map_namesObject



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

def list_bidi_map_names
  list = []
  list += @bidi_maps.collect{|m| "#{m.left.clazz}-to-from-#{m.right.clazz}"}
  return list
end

#list_map_names(full_list = false) ⇒ Object



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

def list_map_names(full_list = false)
  list = []
  list += @maps.collect{|m| "#{m.from.clazz}-to-#{m.to.clazz}"}
  list += @maps.collect{|m|m.from.clazz} if full_list
  return list
end