Class: KivaApi::LoanResponse
- Inherits:
-
Object
- Object
- KivaApi::LoanResponse
- Defined in:
- lib/kiva_api/loan_response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #arrears_amount ⇒ Object
- #basket_amount ⇒ Object
- #business_name ⇒ Object
- #delinquent? ⇒ Boolean
- #expiration_date ⇒ Object
- #funded_amount ⇒ Object
- #id ⇒ Object
-
#initialize(parsed_response) ⇒ LoanResponse
constructor
A new instance of LoanResponse.
- #loan_amount ⇒ Object
- #loan_amount_left_to_purchase ⇒ Object
- #paid_amount ⇒ Object
- #percent_purchased ⇒ Object
- #privately_fundraising? ⇒ Boolean
- #properties ⇒ Object
- #purchased_amount ⇒ Object
- #required_pfp_lenders ⇒ Object
- #state ⇒ Object
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
#response ⇒ Object (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_amount ⇒ Object
16 17 18 |
# File 'lib/kiva_api/loan_response.rb', line 16 def arrears_amount properties['arrearsAmount']['amount'].to_f || 0 end |
#basket_amount ⇒ Object
36 37 38 |
# File 'lib/kiva_api/loan_response.rb', line 36 def basket_amount properties['basketAmount']['amount'].to_f end |
#business_name ⇒ Object
56 57 58 |
# File 'lib/kiva_api/loan_response.rb', line 56 def business_name properties['businessName'] || properties['partnerName'] end |
#delinquent? ⇒ Boolean
24 25 26 |
# File 'lib/kiva_api/loan_response.rb', line 24 def delinquent? state == 'defaulted' end |
#expiration_date ⇒ Object
48 49 50 |
# File 'lib/kiva_api/loan_response.rb', line 48 def expiration_date properties['plannedExpirationDate'] end |
#funded_amount ⇒ Object
32 33 34 |
# File 'lib/kiva_api/loan_response.rb', line 32 def funded_amount properties['fundedAmount']['amount'].to_f end |
#id ⇒ Object
12 13 14 |
# File 'lib/kiva_api/loan_response.rb', line 12 def id properties['id'].to_i end |
#loan_amount ⇒ Object
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_purchase ⇒ Object
60 61 62 |
# File 'lib/kiva_api/loan_response.rb', line 60 def loan_amount_left_to_purchase loan_amount - purchased_amount end |
#paid_amount ⇒ Object
40 41 42 |
# File 'lib/kiva_api/loan_response.rb', line 40 def paid_amount properties['paidAmount']['amount'].to_f end |
#percent_purchased ⇒ Object
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
44 45 46 |
# File 'lib/kiva_api/loan_response.rb', line 44 def privately_fundraising? properties['inPfp'] || false end |
#properties ⇒ Object
8 9 10 |
# File 'lib/kiva_api/loan_response.rb', line 8 def properties response['properties'] end |
#purchased_amount ⇒ Object
64 65 66 |
# File 'lib/kiva_api/loan_response.rb', line 64 def purchased_amount funded_amount + basket_amount end |
#required_pfp_lenders ⇒ Object
52 53 54 |
# File 'lib/kiva_api/loan_response.rb', line 52 def required_pfp_lenders properties['pfpMinLenders'] || 0 end |
#state ⇒ Object
20 21 22 |
# File 'lib/kiva_api/loan_response.rb', line 20 def state properties['status'] end |