class Crowdfund::Project

Attributes

funds[R]
goal[R]
name[RW]

Public Class Methods

new(name, funds=0, goal=0) click to toggle source
# File lib/crowdfund/project.rb, line 9
def initialize(name, funds=0, goal=0)
    @name = name.upcase
    @funds = funds
    @goal = goal
  @pledges = Hash.new(0)
end

Public Instance Methods

<=>(other_project) click to toggle source
# File lib/crowdfund/project.rb, line 41
def <=>(other_project)
  other_project.funds_still_needed <=> funds_still_needed
end
each_pledge_level() { |pledge| ... } click to toggle source
# File lib/crowdfund/project.rb, line 27
def each_pledge_level
  @pledges.each do |name, amount|
    yield Pledge.new(name, amount)
  end
end
funding_pledged() click to toggle source
# File lib/crowdfund/project.rb, line 33
def funding_pledged
  @funds + pledge_amounts
end
name=(new_name) click to toggle source
# File lib/crowdfund/project.rb, line 37
def name=(new_name)
  @name=new_name.upcase
end
pledge_amounts() click to toggle source
# File lib/crowdfund/project.rb, line 23
def pledge_amounts
  @pledges.values.reduce(0, :+)
end
received_pledge(pledge) click to toggle source
# File lib/crowdfund/project.rb, line 16
def received_pledge(pledge)
  @pledges[pledge.name] += pledge.amount

  puts "Project #{@name} received a #{pledge.name} pledge worth $#{pledge.amount}."  
  puts "Project #{name}'s pledges: #{@pledges}"   
end
to_s() click to toggle source
# File lib/crowdfund/project.rb, line 45
def to_s
    "Project #{@name} has $#{funding_pledged} in funds towards a goal of $#{@goal} with $#{funds_still_needed} to be raised."
end