class ShriftMapper

I map ShriftMaps

Attributes

schema[R]

Public Class Methods

new(schema: {}) click to toggle source
# File lib/shrift/shrift_mapper.rb, line 7
def initialize(schema: {})
  @schema = schema
  clean
end

Public Instance Methods

fetch(key) click to toggle source
# File lib/shrift/shrift_mapper.rb, line 12
def fetch(key)
  @schema[key.downcase.to_sym]
end
parse(shrift_map_string) click to toggle source
# File lib/shrift/shrift_mapper.rb, line 20
def parse(shrift_map_string)
  Hash[ShriftMap.new(shrift_map_string).schema.map { |key, val| [@schema[key], val] }]
end
process(target) click to toggle source

Shrift Cell Methods

# File lib/shrift/shrift_mapper.rb, line 43
def process(target)
  to_shrift_string(target)
end
set(value, target) click to toggle source

:reek: UncommunicativeVariableName

# File lib/shrift/shrift_mapper.rb, line 48
def set(value, target)
  shrift_map = to_shrift_map(value)
  @schema.map { |k, v| target.send("#{v}=", shrift_map.fetch(k)) }
end
store(key, value) click to toggle source
# File lib/shrift/shrift_mapper.rb, line 16
def store(key, value)
  @schema[key] = value
end
to_hash() click to toggle source
# File lib/shrift/shrift_mapper.rb, line 24
def to_hash
  @schema
end
to_shrift_map(mappie) click to toggle source
# File lib/shrift/shrift_mapper.rb, line 37
def to_shrift_map(mappie)
  ShriftMap.new(to_shrift_string(mappie))
end
to_shrift_string(mappie) click to toggle source

:reek: UncommunicativeVariableName :reek:FeatureEnvy

# File lib/shrift/shrift_mapper.rb, line 29
def to_shrift_string(mappie)
  return mappie if mappie.is_a?(String)

  return mappie.map { |k, v| @schema.key(k).to_s.downcase + v.to_s }.join if mappie.is_a?(Hash)

  @schema.map { |k, v| k.to_s.downcase + mappie.send(v).to_s }.join
end

Private Instance Methods

clean() click to toggle source

Convert Hash keys to symbols

# File lib/shrift/shrift_mapper.rb, line 56
def clean
  @schema = Hash[@schema.map { |key, value| [key.downcase.to_sym, value] }]
end