Module: CrowdFund::Pledgeable

Included in:
Project
Defined in:
lib/crowdfund/pledgeable.rb

Instance Method Summary collapse

Instance Method Details

#each_pledgeObject



9
10
11
12
13
# File 'lib/crowdfund/pledgeable.rb', line 9

def each_pledge
  pledges.each do |name, amount|
    yield Pledge.new(name, amount)
  end
end

#make_pledge(pledge) ⇒ Object



3
4
5
6
7
# File 'lib/crowdfund/pledgeable.rb', line 3

def make_pledge(pledge)
  self.pledges[pledge.name] += pledge.amount
  puts "Project #{name} received a #{pledge.name} pledge worth $#{pledge.amount}"
  puts "Project #{name}'s pledges: #{pledges}"
end

#pledged_fundsObject



15
16
17
# File 'lib/crowdfund/pledgeable.rb', line 15

def pledged_funds
  pledges.values.reduce(0) { |sum, amount| sum + amount }
end

#total_fundsObject



19
20
21
# File 'lib/crowdfund/pledgeable.rb', line 19

def total_funds
  funding + pledged_funds
end