Class: KivaApi::LoanResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/kiva_api/loan_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_response) ⇒ LoanResponse

Returns a new instance of LoanResponse.



4
5
6
# File 'lib/kiva_api/loan_response.rb', line 4

def initialize(parsed_response)
  @response = parsed_response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



2
3
4
# File 'lib/kiva_api/loan_response.rb', line 2

def response
  @response
end

Instance Method Details

#arrears_amountObject



16
17
18
# File 'lib/kiva_api/loan_response.rb', line 16

def arrears_amount
  properties['arrearsAmount']['amount'].to_f || 0
end

#basket_amountObject



36
37
38
# File 'lib/kiva_api/loan_response.rb', line 36

def basket_amount
  properties['basketAmount']['amount'].to_f
end

#business_nameObject



56
57
58
# File 'lib/kiva_api/loan_response.rb', line 56

def business_name
  properties['businessName'] || properties['partnerName']
end

#delinquent?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/kiva_api/loan_response.rb', line 24

def delinquent?
  state == 'defaulted'
end

#expiration_dateObject



48
49
50
# File 'lib/kiva_api/loan_response.rb', line 48

def expiration_date
  properties['plannedExpirationDate']
end

#funded_amountObject



32
33
34
# File 'lib/kiva_api/loan_response.rb', line 32

def funded_amount
  properties['fundedAmount']['amount'].to_f
end

#idObject



12
13
14
# File 'lib/kiva_api/loan_response.rb', line 12

def id
  properties['id'].to_i
end

#loan_amountObject



28
29
30
# File 'lib/kiva_api/loan_response.rb', line 28

def loan_amount
  properties['loanAmount']['amount'].to_f
end

#loan_amount_left_to_purchaseObject



60
61
62
# File 'lib/kiva_api/loan_response.rb', line 60

def loan_amount_left_to_purchase
  loan_amount - purchased_amount
end


40
41
42
# File 'lib/kiva_api/loan_response.rb', line 40

def paid_amount
  properties['paidAmount']['amount'].to_f
end

#percent_purchasedObject



68
69
70
# File 'lib/kiva_api/loan_response.rb', line 68

def percent_purchased
  (purchased_amount / loan_amount) * 100.0
end

#privately_fundraising?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/kiva_api/loan_response.rb', line 44

def privately_fundraising?
  properties['inPfp'] || false
end

#propertiesObject



8
9
10
# File 'lib/kiva_api/loan_response.rb', line 8

def properties
  response['properties']
end

#purchased_amountObject



64
65
66
# File 'lib/kiva_api/loan_response.rb', line 64

def purchased_amount
  funded_amount + basket_amount
end

#required_pfp_lendersObject



52
53
54
# File 'lib/kiva_api/loan_response.rb', line 52

def required_pfp_lenders
  properties['pfpMinLenders'] || 0
end

#stateObject



20
21
22
# File 'lib/kiva_api/loan_response.rb', line 20

def state
  properties['status']
end