Class: Bs2Api::Entities::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/entities/account.rb

Constant Summary collapse

TYPES =
{
  checking: 'ContaCorrente',
  salary: 'ContaSalario',
  saving: 'Poupanca'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Account

Returns a new instance of Account.



14
15
16
17
18
19
20
# File 'lib/bs2_api/entities/account.rb', line 14

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

Instance Attribute Details

#agencyObject

Returns the value of attribute agency.



6
7
8
# File 'lib/bs2_api/entities/account.rb', line 6

def agency
  @agency
end

#bank_codeObject

Returns the value of attribute bank_code.



6
7
8
# File 'lib/bs2_api/entities/account.rb', line 6

def bank_code
  @bank_code
end

#bank_nameObject

Returns the value of attribute bank_name.



6
7
8
# File 'lib/bs2_api/entities/account.rb', line 6

def bank_name
  @bank_name
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/bs2_api/entities/account.rb', line 6

def number
  @number
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/bs2_api/entities/account.rb', line 6

def type
  @type
end

Class Method Details

.from_response(hash_payload) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bs2_api/entities/account.rb', line 34

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

Instance Method Details

#checking?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/bs2_api/entities/account.rb', line 46

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

#salary?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bs2_api/entities/account.rb', line 50

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

#saving?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/bs2_api/entities/account.rb', line 54

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

#to_hashObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bs2_api/entities/account.rb', line 22

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