class CrowdFund::Project
Attributes
funding[RW]
name[RW]
target_funding[R]
Public Class Methods
new(name, target_funding, funding=0)
click to toggle source
# File lib/crowdfund/project.rb, line 11 def initialize(name, target_funding, funding=0) @name = name @target_funding = target_funding @funding = funding @pledges_received = Hash.new(0) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/crowdfund/project.rb, line 22 def <=>(other) other.funding_needed <=> funding_needed end
each_received_pledge() { |pledge| ... }
click to toggle source
# File lib/crowdfund/project.rb, line 33 def each_received_pledge @pledges_received.each do |name, amount| yield Pledge.new(name, amount) end end
received_pledge(pledge)
click to toggle source
# File lib/crowdfund/project.rb, line 26 def received_pledge(pledge) @pledges_received[pledge.name] += pledge.amount @funding += pledge.amount puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.amount}." puts "#{@name}'s pledges: #{@pledges_received}" end
to_s()
click to toggle source
# File lib/crowdfund/project.rb, line 18 def to_s "#{@name} has $#{@funding} in funding towards a goal of $#{@target_funding}, i.e. $#{funding_needed} is still needed." end
total_pledges()
click to toggle source
# File lib/crowdfund/project.rb, line 39 def total_pledges @pledges_received.values.reduce(0, :+) end