Sha256: 9fb7ea63a5b9cf81f672a526431ba60fcfe705d7a7fdcf9c4c8b1b8a3956e5b7

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Bs2Api
  module Entities
    class Bank
      attr_accessor :ispb, :account, :customer

      def initialize(args = {})
        @ispb     = args.fetch(:ispb, nil)
        @account  = args.fetch(:account, nil)
        @customer = args.fetch(:customer, nil)
      end

      def to_hash
        ActiveSupport::HashWithIndifferentAccess.new(
          {
            "ispb": get_ispb,
            "conta": @account.to_hash,
            "pessoa": @customer.to_hash
          }
        )
      end

      def self.from_response(hash_payload)
        hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)

        Bs2Api::Entities::Bank.new(
          ispb: hash["ispb"],
          account: Bs2Api::Entities::Account.from_response(hash["conta"]),
          customer: Bs2Api::Entities::Customer.from_response(hash["pessoa"])
        )
      end

      private
        def get_ispb
          Bs2Api::Util::BankService.find_by_code(@account.bank_code)["ispb"]
        end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bs2_api-1.0.3 lib/bs2_api/entities/bank.rb
bs2_api-1.0.2 lib/bs2_api/entities/bank.rb
bs2_api-1.0.1 lib/bs2_api/entities/bank.rb
bs2_api-1.0.0 lib/bs2_api/entities/bank.rb
bs2_api-0.4.0 lib/bs2_api/entities/bank.rb
bs2_api-0.3.4 lib/bs2_api/entities/bank.rb
bs2_api-0.3.3 lib/bs2_api/entities/bank.rb
bs2_api-0.3.2 lib/bs2_api/entities/bank.rb
bs2_api-0.3.1 lib/bs2_api/entities/bank.rb
bs2_api-0.3.0 lib/bs2_api/entities/bank.rb
bs2_api-0.2.1 lib/bs2_api/entities/bank.rb
bs2_api-0.2.0 lib/bs2_api/entities/bank.rb