Sha256: 998e947009f6a420016914492d2c5a4eed637e994bf5b9cd6d6e37273a60aa05
Contents?: true
Size: 841 Bytes
Versions: 1
Compression:
Stored size: 841 Bytes
Contents
class Exchequer::ErrorMapper MAPPINGS = { 'Credit card expiration year' => :expiration_year, 'Credit card expiration month' => :expiration_month, 'Credit card number' => :full_number, 'First name' => :first_name, 'Last name' => :last_name } def self.map(source, arguments) new(source, arguments[:to]).map_errors end def initialize(source, destination) @source, @destination = source, destination end def map_errors source.errors[:base].dup.each do |error| label = MAPPINGS.keys.detect { |key| error[/^#{key}:/] } if label destination.errors[MAPPINGS[label]] << error.gsub(/^#{label}:\s+/, '') else destination.errors[:base] << error end end end private attr_reader :source, :destination end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
exchequer-0.1.0 | lib/exchequer/error_mapper.rb |