Class: AdvisorsCommandClient::Models::Base
- Inherits:
-
Object
- Object
- AdvisorsCommandClient::Models::Base
- Defined in:
- lib/advisors_command_client/models/base.rb
Class Method Summary collapse
-
.deep_underscore_params(val = {}) ⇒ Object
JSON comes back as SnakeCase.
- .load(hash, connection = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(args, connection = nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(args, connection = nil) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 |
# File 'lib/advisors_command_client/models/base.rb', line 11 def initialize(args, connection = nil) super(args) @original_hash = args @connection = connection end |
Class Method Details
.deep_underscore_params(val = {}) ⇒ Object
JSON comes back as SnakeCase. This will convert all hash keys to snake_case.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/advisors_command_client/models/base.rb', line 19 def self.deep_underscore_params(val = {}) snake_caser = -> val {val.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase} case val when Array val.map { |v| deep_underscore_params(v) } when Hash val.keys.each do |k, v = val[k]| val.delete k val[snake_caser.call(k)] = deep_underscore_params(v) end params = val else val end return val end |
.load(hash, connection = nil) ⇒ Object
6 7 8 9 |
# File 'lib/advisors_command_client/models/base.rb', line 6 def self.load(hash, connection = nil) hash = deep_underscore_params(hash) new(hash, connection) end |