Skip to content

Instantly share code, notes, and snippets.

@luxflux
Last active August 29, 2015 14:27
Show Gist options
  • Save luxflux/42e9cdc92892c21dcbda to your computer and use it in GitHub Desktop.
Save luxflux/42e9cdc92892c21dcbda to your computer and use it in GitHub Desktop.
class MappingTest
MAPPING = {
passengers: ->(hash) { hash[:customer_info][:person_name] },
flight_ticket_selling_carrier: :extract_services,
}
def results
response = api_call
res = {}
MAPPING.each do |attribute, extraction|
res[attribute] = if extraction.respond_to?(:call)
extraction.call(response) # call proc or lambda
else
send(response) # call method defined on the class
end
end
res
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment