Class: UnionPay::Core::Utils
- Inherits:
-
Object
- Object
- UnionPay::Core::Utils
- Defined in:
- lib/union-pay/core/utils.rb
Class Method Summary collapse
- .check_hash_keys!(hash, *keys) ⇒ Object
- .decode_reserved(str) ⇒ Object
- .encode_reserved(kv) ⇒ Object
- .key_to_sym(kv) ⇒ Object
Class Method Details
.check_hash_keys!(hash, *keys) ⇒ Object
11 12 13 14 15 |
# File 'lib/union-pay/core/utils.rb', line 11 def check_hash_keys!(hash, *keys) keys.flatten.each do |key| raise ArgumentError.new("Unknown key: #{key.inspect}") unless hash.has_key?(key) end end |
.decode_reserved(str) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/union-pay/core/utils.rb', line 21 def decode_reserved(str) return str unless str.is_a?(String) result = URI.decode_www_form(str[1..-2]) result = Hash[result] key_to_sym(result) end |
.encode_reserved(kv) ⇒ Object
17 18 19 |
# File 'lib/union-pay/core/utils.rb', line 17 def encode_reserved(kv) "{#{URI.encode_www_form(kv)}}" end |
.key_to_sym(kv) ⇒ Object
7 8 9 |
# File 'lib/union-pay/core/utils.rb', line 7 def key_to_sym(kv) kv.inject({}){|memo, (k,v)| memo[k.to_sym] = v; memo} end |