class Vantiv::Certification::CertRequestBodyCompiler

Attributes

matchers[RW]

Public Class Methods

new(*matchers) click to toggle source
# File lib/vantiv/certification/cert_request_body_compiler.rb, line 6
def initialize(*matchers)
  @matchers = matchers
end

Public Instance Methods

compile(hash) click to toggle source
# File lib/vantiv/certification/cert_request_body_compiler.rb, line 10
def compile(hash)
  dup = {}
  hash.each do |key, value|
    if value.is_a?(Hash)
      dup[key] = compile(value)
    else
      dup[key] = compile_value(value)
    end
  end
  dup
end

Private Instance Methods

compile_value(value) click to toggle source
# File lib/vantiv/certification/cert_request_body_compiler.rb, line 24
def compile_value(value)
  matchers.each do |matcher|
    if matches = matcher[:regex].match(value)
      matches = matches.to_a
      matches.shift
      matches.each do |match|
        value = matcher[:fetcher].call(value, match)
      end
    end
  end
  value
end