Module: Hyperb::Utils
- Defined in:
- lib/hyperb/utils.rb
Overview
utils functions
Instance Method Summary collapse
-
#check_arguments(params, *args) ⇒ Boolean
checks if all args are keys into the hash.
-
#downcase_symbolize(obj) ⇒ Object
hyper.sh responses are capital cased json.
Instance Method Details
#check_arguments(params, *args) ⇒ Boolean
checks if all args are keys into the hash
10 11 12 13 14 15 16 |
# File 'lib/hyperb/utils.rb', line 10 def check_arguments(params, *args) contains = true args.each do |arg| contains = false unless params.key? arg.to_sym end contains end |
#downcase_symbolize(obj) ⇒ Object
hyper.sh responses are capital cased json
“value”
this fn is used to symbolize and downcase all hyper.sh api reponses
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hyperb/utils.rb', line 23 def downcase_symbolize(obj) if obj.is_a? Hash return obj.each_with_object({}) do |(k, v), memo| memo.tap { |m| m[k.downcase.to_sym] = downcase_symbolize(v) } end end if obj.is_a? Array return obj.each_with_object([]) do |v, memo| memo << downcase_symbolize(v) memo end end obj end |