Sha256: 83f1280e6da62197fe87b61b7240427a9aa4c6315c99d606906285563dba5245
Contents?: true
Size: 1009 Bytes
Versions: 4
Compression:
Stored size: 1009 Bytes
Contents
# frozen_string_literal: true module Fawry module Utils TRUTH_VALUES = [true, 'true', '1', 't'].freeze # Adds keys from fawry API response as methods # on object instance that return the value # of each key # # type => type # referenceNumber => reference_number # merchantRefNumber => merchant_ref_number # expirationTime => expiration_time # statusCode => status_code # statusDescription => status_description # # fawry_res = FawryResponse.new(response) # fawry_res.status_code => 200 # fawry_res.reference_number => 1234567 def enrich_object(fawry_params) fawry_params.each_key do |key| method_name = key.to_s.split(/(?=[A-Z])/).map(&:downcase).join('_') # statusCode => status_code instance_variable_set("@#{method_name}", fawry_params[key]) method_body = proc { instance_variable_get("@#{method_name}") } self.class.public_send(:define_method, method_name, method_body) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fawry-1.4.1 | lib/fawry/utils.rb |
fawry-1.4.0 | lib/fawry/utils.rb |
fawry-1.3.1 | lib/fawry/utils.rb |
fawry-1.3.0 | lib/fawry/utils.rb |