Class: TableStructure::Schema::KeyConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/schema/key_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(prefix: nil, suffix: nil) ⇒ KeyConverter

Returns a new instance of KeyConverter.



6
7
8
9
# File 'lib/table_structure/schema/key_converter.rb', line 6

def initialize(prefix: nil, suffix: nil)
  @prefix = prefix
  @suffix = suffix
end

Instance Method Details

#convert(keys) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/table_structure/schema/key_converter.rb', line 11

def convert(keys)
  return keys unless has_any_options?

  keys.map do |key|
    next key unless key

    decorated_key = "#{@prefix}#{key}#{@suffix}"
    key.is_a?(Symbol) ? decorated_key.to_sym : decorated_key
  end
end