Class: CommandMapper::Gen::Types::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/command_mapper/gen/types/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ Map

Initializes the map type.

Parameters:

  • map (Hash{Object => String})


14
15
16
# File 'lib/command_mapper/gen/types/map.rb', line 14

def initialize(map)
  @map = map
end

Instance Attribute Details

#mapHash{Object => String} (readonly)

Returns:

  • (Hash{Object => String})


7
8
9
# File 'lib/command_mapper/gen/types/map.rb', line 7

def map
  @map
end

Instance Method Details

#to_rubyString

Converts the map type to Ruby source code.

Returns:

  • (String)


23
24
25
26
27
28
29
30
31
# File 'lib/command_mapper/gen/types/map.rb', line 23

def to_ruby
  pairs = []

  @map.each do |value,string|
    pairs << "#{value.inspect} => #{string.inspect}"
  end

  return "Map.new(#{pairs.join(', ')})"
end