Class: FundraisingProgram::HalfWayProject
- Defined in:
- lib/fundraising_program/half_way_project.rb
Instance Attribute Summary
Attributes inherited from Project
#funding, #name, #pledges_accumulated, #target_funding
Instance Method Summary collapse
- #add_fund ⇒ Object
- #add_pledge(pledge) ⇒ Object
- #half_way_reached?(funding1, funding2) ⇒ Boolean
-
#initialize(name, funding, target_funding, extra_funding = 500) ⇒ HalfWayProject
constructor
A new instance of HalfWayProject.
Methods inherited from Project
#<=>, #each_pledge, from_csv, #funding_left, #pledges_amount, #to_s, #total_funds
Methods included from Fundable
Constructor Details
#initialize(name, funding, target_funding, extra_funding = 500) ⇒ HalfWayProject
Returns a new instance of HalfWayProject.
6 7 8 9 |
# File 'lib/fundraising_program/half_way_project.rb', line 6 def initialize(name, funding, target_funding, extra_funding=500) super(name,funding,target_funding) @extra_funding = extra_funding end |
Instance Method Details
#add_fund ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fundraising_program/half_way_project.rb', line 15 def add_fund funding1 = total_funds super funding2 = total_funds if half_way_reached?(funding1, funding2) @funding += @extra_funding end end |
#add_pledge(pledge) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/fundraising_program/half_way_project.rb', line 24 def add_pledge(pledge) funding1 = total_funds super(pledge) funding2 = total_funds if half_way_reached?(funding1, funding2) @funding += @extra_funding end end |
#half_way_reached?(funding1, funding2) ⇒ Boolean
11 12 13 |
# File 'lib/fundraising_program/half_way_project.rb', line 11 def half_way_reached?(funding1, funding2) (funding1 < target_funding / 2) && (funding2 >= target_funding/2) end |