Class: Bvr::Credit

Inherits:
Struct
  • Object
show all
Defined in:
lib/bvr/credit.rb

Constant Summary collapse

API_COMMANDS =
{
  add: 'settransaction'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#customerObject

Returns the value of attribute customer

Returns:

  • (Object)

    the current value of customer



2
3
4
# File 'lib/bvr/credit.rb', line 2

def customer
  @customer
end

#raw_balanceObject

Returns the value of attribute raw_balance

Returns:

  • (Object)

    the current value of raw_balance



2
3
4
# File 'lib/bvr/credit.rb', line 2

def raw_balance
  @raw_balance
end

#raw_specific_balanceObject

Returns the value of attribute raw_specific_balance

Returns:

  • (Object)

    the current value of raw_specific_balance



2
3
4
# File 'lib/bvr/credit.rb', line 2

def raw_specific_balance
  @raw_specific_balance
end

Class Method Details

.add(id, amount) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/bvr/credit.rb', line 7

def self.add(id, amount)
  params = {
    command: API_COMMANDS[:add],
    customer: id,
    amount: amount
  }

  Bvr.connection.get(params)
end

Instance Method Details

#add(amount) ⇒ Object



17
18
19
20
21
22
# File 'lib/bvr/credit.rb', line 17

def add(amount)
  response = Bvr::Credit.add(self.customer.id, amount)
  return false unless response['Result'] == 'Success'

  add_amount(amount) && true
end

#balanceObject



25
26
27
# File 'lib/bvr/credit.rb', line 25

def balance
  @_balance ||= Float(self.raw_balance)
end

#rm(amount) ⇒ Object



29
30
31
# File 'lib/bvr/credit.rb', line 29

def rm(amount)
  self.add(-1 * amount)
end

#specific_balanceObject



33
34
35
# File 'lib/bvr/credit.rb', line 33

def specific_balance
  @_specific_balance ||= Float(self.raw_specific_balance)
end