Class: CrowdFund::Project
- Inherits:
-
Object
- Object
- CrowdFund::Project
- Includes:
- Fundable, Pledgeable
- Defined in:
- lib/crowdfund/project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#funding ⇒ Object
Returns the value of attribute funding.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pledges ⇒ Object
Returns the value of attribute pledges.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(name, target, funding = 0) ⇒ Project
constructor
A new instance of Project.
- #outstanding_funding ⇒ Object
- #status ⇒ Object
- #to_s ⇒ Object
Methods included from Pledgeable
#each_pledge, #make_pledge, #pledged_funds, #total_funds
Methods included from Fundable
#<=>, #add_funds, #fully_funded?, #remove_funds
Constructor Details
#initialize(name, target, funding = 0) ⇒ Project
Returns a new instance of Project.
12 13 14 15 16 17 |
# File 'lib/crowdfund/project.rb', line 12 def initialize(name, target, funding=0) @name = name @funding = funding @target = target @pledges = Hash.new(0) end |
Instance Attribute Details
#funding ⇒ Object
Returns the value of attribute funding.
10 11 12 |
# File 'lib/crowdfund/project.rb', line 10 def funding @funding end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/crowdfund/project.rb', line 10 def name @name end |
#pledges ⇒ Object
Returns the value of attribute pledges.
10 11 12 |
# File 'lib/crowdfund/project.rb', line 10 def pledges @pledges end |
#target ⇒ Object
Returns the value of attribute target.
10 11 12 |
# File 'lib/crowdfund/project.rb', line 10 def target @target end |
Instance Method Details
#outstanding_funding ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/crowdfund/project.rb', line 19 def outstanding_funding if fully_funded? 0 else @target - total_funds end end |
#status ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/crowdfund/project.rb', line 27 def status status = "\n#{@name} funded including pledges at $#{total_funds} for $#{@target} target" status += "\nProject #{@name}'s pledges:" each_pledge do |pledge| status += "\n$#{pledge.amount} in #{pledge.name} pledges" end status += "\n$#{pledged_funds} in total pledges" end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/crowdfund/project.rb', line 36 def to_s "Project #{@name} has $#{@funding} in funding towards a goal of $#{@target}" end |