Class: BridgeBankin::BridgeObject
- Inherits:
-
Object
- Object
- BridgeBankin::BridgeObject
- Defined in:
- lib/bridge_bankin/bridge_object.rb
Overview
BridgeObject is the base class from which all other more specific BridgeBankin resources derive.
Direct Known Subclasses
Account, Bank, Category, Connect, Insight, Item, Stock, Transaction, Transfer, User
Constant Summary collapse
- HIDDEN_ATTRIBUTES =
%i[resource_type resource_uri].freeze
Class Method Summary collapse
-
.convert_to_bridge_object(data) ⇒ Account, ...
Convert any API response body with its corresponding resource object if exists.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(**attrs) ⇒ BridgeObject
constructor
Initializes BridgeObject.
- #to_hash ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(**attrs) ⇒ BridgeObject
Initializes BridgeObject
15 16 17 |
# File 'lib/bridge_bankin/bridge_object.rb', line 15 def initialize(**attrs) define_instance_variables(attrs) end |
Class Method Details
.convert_to_bridge_object(data) ⇒ Account, ...
Convert any API response body with its corresponding resource object if exists
27 28 29 30 31 32 33 34 35 |
# File 'lib/bridge_bankin/bridge_object.rb', line 27 def convert_to_bridge_object(data) if data[:resources] data[:resources].map { |resource| convert_to_bridge_object(resource) } elsif data.is_a?(Array) data.map { |val| convert_to_bridge_object(val) } else object_from_resource_type(data) end end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 |
# File 'lib/bridge_bankin/bridge_object.rb', line 66 def ==(other) other.is_a?(BridgeObject) && to_hash == other.to_hash end |
#to_hash ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bridge_bankin/bridge_object.rb', line 48 def to_hash instance_variables.each_with_object({}) do |var, hash| hash[var.to_s.delete("@")] = case instance_variable_get(var) when BridgeObject instance_variable_get(var).to_hash when Array instance_variable_get(var).map { |val| val.is_a?(BridgeObject) ? val.to_hash : val } else instance_variable_get(var) end end.transform_keys!(&:to_sym) end |
#to_json(*_args) ⇒ Object
62 63 64 |
# File 'lib/bridge_bankin/bridge_object.rb', line 62 def to_json(*_args) to_hash.to_json end |