Sha256: 2207f123fb5bfc5a0e0b7accb058470cfb836caf01217d3bfae64775af6187d7

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Bs2Api
  module Entities
    class Account
      attr_accessor :bank_code, :bank_name, :agency, :number, :type
  
      TYPES = {
        checking: 'ContaCorrente',
        salary: 'ContaSalario',
        saving: 'Poupanca'
      }

      def initialize(args = {})
        @bank_code  = args.fetch(:bank_code, nil)
        @bank_name  = args.fetch(:bank_name, nil)
        @agency     = args.fetch(:agency, nil)
        @number     = args.fetch(:number, nil)
        @type       = args.fetch(:type, nil)
      end

      def to_hash
        ActiveSupport::HashWithIndifferentAccess.new(
          {
            "banco": @bank_code,
            "bancoNome": @bank_name,
            "agencia": @agency,
            "numero": @number,
            "tipo": @type
          }
        )
      end

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

        Bs2Api::Entities::Account.new(
          bank_code: hash["banco"],
          bank_name: hash["bancoNome"],
          agency: hash["agencia"],
          number: hash["numero"],
          type: hash["tipo"]
        )
      end

      def checking?
        @type == TYPES[:checking]
      end

      def salary?
        @type == TYPES[:salary]
      end

      def saving?
        @type == TYPES[:saving]
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bs2_api-1.9.0 lib/bs2_api/entities/account.rb
bs2_api-1.8.0 lib/bs2_api/entities/account.rb
bs2_api-1.7.0 lib/bs2_api/entities/account.rb
bs2_api-1.6.2 lib/bs2_api/entities/account.rb
bs2_api-1.6.1 lib/bs2_api/entities/account.rb
bs2_api-1.6.0 lib/bs2_api/entities/account.rb
bs2_api-1.5.1 lib/bs2_api/entities/account.rb
bs2_api-1.5.0 lib/bs2_api/entities/account.rb
bs2_api-1.4.3 lib/bs2_api/entities/account.rb
bs2_api-1.4.2 lib/bs2_api/entities/account.rb
bs2_api-1.4.1 lib/bs2_api/entities/account.rb
bs2_api-1.4.0 lib/bs2_api/entities/account.rb
bs2_api-1.2.2 lib/bs2_api/entities/account.rb
bs2_api-1.2.1 lib/bs2_api/entities/account.rb
bs2_api-1.2.0 lib/bs2_api/entities/account.rb