class TalentScout::ChoiceType

@!visibility private

Attributes

mapping[R]

Public Class Methods

new(mapping) click to toggle source
# File lib/talent_scout/choice_type.rb, line 7
def initialize(mapping)
  @mapping = if mapping.is_a?(Hash)
    unless mapping.all?{|key, value| key.is_a?(String) || key.is_a?(Symbol) }
      raise ArgumentError, "Only String and Symbol keys are supported"
    end
    mapping.stringify_keys
  else
    mapping.index_by(&:to_s)
  end
end

Public Instance Methods

cast(value) click to toggle source
Calls superclass method
# File lib/talent_scout/choice_type.rb, line 23
def cast(value)
  key = value.to_s if value.is_a?(String) || value.is_a?(Symbol)
  if @mapping.key?(key)
    super(@mapping[key])
  elsif @mapping.value?(value)
    super(value)
  end
end
initialize_copy(orig) click to toggle source
Calls superclass method
# File lib/talent_scout/choice_type.rb, line 18
def initialize_copy(orig)
  super
  @mapping = @mapping.dup
end