class CrowdFund::Project
Attributes
funding[R]
name[RW]
target[R]
Public Class Methods
new(name, funding=0, target)
click to toggle source
# File lib/crowdfund/project.rb, line 9 def initialize(name, funding=0, target) @name= name @funding= funding @target= target @pledges_made= Hash.new(0) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/crowdfund/project.rb, line 24 def <=>(other) other.funding_needed <=> funding_needed end
each_pledge_donated() { |pledges| ... }
click to toggle source
# File lib/crowdfund/project.rb, line 34 def each_pledge_donated @pledges_made.each do |level, amount| yield Pledges.new(level, amount) end end
funded?()
click to toggle source
# File lib/crowdfund/project.rb, line 20 def funded? @funding >= @target end
funding_needed()
click to toggle source
# File lib/crowdfund/project.rb, line 44 def funding_needed @target - @funding end
funds()
click to toggle source
# File lib/crowdfund/project.rb, line 40 def funds @pledges_made.values.reduce(0, :+) end
pledges_made(pledge)
click to toggle source
# File lib/crowdfund/project.rb, line 28 def pledges_made(pledge) @pledges_made[pledge.level] += pledge.amount puts "Project #{@name} received a #{pledge.level} pledge worth $#{pledge.amount}." puts "Project #{@name}'s pledges: #{@pledges_made}" end
to_s()
click to toggle source
# File lib/crowdfund/project.rb, line 16 def to_s "Project #{@name} has $#{@funding} in funding towards a goal of $#{@target}, we still need $#{funding_needed} to hit our goal." end