Class: Crowdfunder::Project
- Inherits:
-
Object
- Object
- Crowdfunder::Project
- Includes:
- Fundable
- Defined in:
- lib/crowdfunder/project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fully_funded ⇒ Object
Returns the value of attribute fully_funded.
-
#initial_fund ⇒ Object
Returns the value of attribute initial_fund.
-
#name ⇒ Object
Returns the value of attribute name.
-
#target_fund ⇒ Object
Returns the value of attribute target_fund.
Instance Method Summary collapse
- #each_pledge_received ⇒ Object
- #found_pledge(pledge) ⇒ Object
-
#initialize(name, initial_fund = 0, target_fund) ⇒ Project
constructor
A new instance of Project.
- #pledged_funds ⇒ Object
- #to_s ⇒ Object
- #total_funds ⇒ Object
Methods included from Fundable
#<=>, #add_funds, #fully_funded?, #remove_funds, #total_funding_outstanding, #total_required_funds
Constructor Details
#initialize(name, initial_fund = 0, target_fund) ⇒ Project
Returns a new instance of Project.
12 13 14 15 16 17 |
# File 'lib/crowdfunder/project.rb', line 12 def initialize(name, initial_fund=0, target_fund) @name = name.upcase @target_fund = target_fund @initial_fund = initial_fund @received_pledges = Hash.new(0) end |
Instance Attribute Details
#fully_funded ⇒ Object
Returns the value of attribute fully_funded.
10 11 12 |
# File 'lib/crowdfunder/project.rb', line 10 def fully_funded @fully_funded end |
#initial_fund ⇒ Object
Returns the value of attribute initial_fund.
10 11 12 |
# File 'lib/crowdfunder/project.rb', line 10 def initial_fund @initial_fund end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/crowdfunder/project.rb', line 9 def name @name end |
#target_fund ⇒ Object
Returns the value of attribute target_fund.
10 11 12 |
# File 'lib/crowdfunder/project.rb', line 10 def target_fund @target_fund end |
Instance Method Details
#each_pledge_received ⇒ Object
42 43 44 45 46 47 |
# File 'lib/crowdfunder/project.rb', line 42 def each_pledge_received @received_pledges.each do |name, amount| pledge = Pledge.new(name, amount) yield pledge end end |
#found_pledge(pledge) ⇒ Object
29 30 31 32 33 |
# File 'lib/crowdfunder/project.rb', line 29 def found_pledge(pledge) @received_pledges[pledge.name] += pledge.amount puts "#{@name} received a #{pledge.name} worth $#{pledge.amount}." puts "#{@name}'s pledges: #{@received_pledges}" end |
#pledged_funds ⇒ Object
23 24 25 26 27 |
# File 'lib/crowdfunder/project.rb', line 23 def pledged_funds # pledge funds is a virtual accessor. in this case it returns the a value # derived from an instance variable (@received_pledges) @received_pledges.values.reduce(0, :+) end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/crowdfunder/project.rb', line 19 def to_s "#{@name} has a goal of #{@target_fund} but has raised a total of $#{total_funds} in funding." end |
#total_funds ⇒ Object
35 36 37 38 39 40 |
# File 'lib/crowdfunder/project.rb', line 35 def total_funds # total_funds is a virtual accessor, in that the total_funds method doesn't return # the value of a @total_funds instances variable. Instead, the total funds are # computed when the method is called. @initial_fund + pledged_funds end |