Class: CrowdFund::Project
- Inherits:
-
Object
- Object
- CrowdFund::Project
- Includes:
- Fundable
- Defined in:
- lib/crowdfund/funds.rb,
lib/crowdfund/project.rb,
lib/crowdfund/startups.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fund ⇒ Object
Returns the value of attribute fund.
-
#goal ⇒ Object
readonly
Returns the value of attribute goal.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #each_earned_pledge ⇒ Object
- #earn_pledge(pledge) ⇒ Object
- #gained ⇒ Object
-
#initialize(name, fund, goal) ⇒ Project
constructor
A new instance of Project.
- #lost ⇒ Object
- #need ⇒ Object
- #rewards ⇒ Object
-
#to_s ⇒ Object
Moved to fundable def gained @fund += 25 puts “Project #@name got more funds!” end def lost @fund -= 15 puts “Project #@name lost some funds!” end def need @goal - @fund end def funded? @fund >= @goal end def <=>(other_project) other_project.need <=> need end.
Methods included from Fundable
Constructor Details
#initialize(name, fund, goal) ⇒ Project
Returns a new instance of Project.
6 7 8 9 10 |
# File 'lib/crowdfund/funds.rb', line 6 def initialize(name, fund, goal) @name = name @fund = fund @goal = goal end |
Instance Attribute Details
#fund ⇒ Object
Returns the value of attribute fund.
4 5 6 |
# File 'lib/crowdfund/funds.rb', line 4 def fund @fund end |
#goal ⇒ Object (readonly)
Returns the value of attribute goal.
4 5 6 |
# File 'lib/crowdfund/funds.rb', line 4 def goal @goal end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/crowdfund/funds.rb', line 3 def name @name end |
Instance Method Details
#each_earned_pledge ⇒ Object
26 27 28 29 30 |
# File 'lib/crowdfund/project.rb', line 26 def each_earned_pledge @earned_pledges.each do |name, amount| yield Pledge.new(name, amount) end end |
#earn_pledge(pledge) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/crowdfund/project.rb', line 19 def earn_pledge(pledge) @earned_pledges[pledge.name] += pledge.amount @fund += pledge.amount puts "#{@name} earned a #{pledge.name} pledge worth $#{pledge.amount}" puts "#{@name}'s pledges: #{@earned_pledges}" end |
#gained ⇒ Object
12 13 14 15 |
# File 'lib/crowdfund/funds.rb', line 12 def gained @fund += 25 puts "Project #{@name} got more funds!" end |
#lost ⇒ Object
17 18 19 20 |
# File 'lib/crowdfund/funds.rb', line 17 def lost @fund -= 15 puts "Project #{@name} lost some funds!" end |
#need ⇒ Object
22 23 24 |
# File 'lib/crowdfund/funds.rb', line 22 def need @goal - @fund end |
#rewards ⇒ Object
32 33 34 |
# File 'lib/crowdfund/project.rb', line 32 def rewards @earned_pledges.values.reduce(0, :+) end |
#to_s ⇒ Object
Moved to fundable
def gained
@fund += 25
puts "Project #{@name} got more funds!"
end
def lost
@fund -= 15
puts "Project #{@name} lost some funds!"
end
def need
@goal - @fund
end
def funded?
@fund >= @goal
end
def <=>(other_project)
other_project.need <=> need
end
55 56 57 |
# File 'lib/crowdfund/project.rb', line 55 def to_s "Project #{@name} has $#{@fund} in fundinfg towards a goal of $#{@goal} => still need $#{need}" end |