class CrowdFund::Project
Attributes
funding[RW]
name[RW]
target[R]
Public Class Methods
from_csv(string)
click to toggle source
# File lib/crowd_fund/project.rb, line 20 def self.from_csv(string) name, funding, target = string.split(',') Project.new(name, Integer(funding), Integer(target)) end
new(name, target_amount, funding=0)
click to toggle source
# File lib/crowd_fund/project.rb, line 13 def initialize(name, target_amount, funding=0) @name = name @target = target_amount @funding = funding @found_pledge = Hash.new(0) end
Public Instance Methods
each_pledge() { |pledge| ... }
click to toggle source
# File lib/crowd_fund/project.rb, line 29 def each_pledge @found_pledge.each do |name, amount| pledge = Pledge.new(name, amount) yield pledge end end
found_pledge(pledge)
click to toggle source
# File lib/crowd_fund/project.rb, line 36 def found_pledge(pledge) @found_pledge[pledge.name] += pledge.amount puts "#{@name} received a #{pledge.name} pledge worth #{pledge.amount}." puts "#{@name}'s pledges: #{@found_pledge} " end
pledges()
click to toggle source
# File lib/crowd_fund/project.rb, line 25 def pledges @found_pledge.values.reduce(0, :+) end
to_s()
click to toggle source
# File lib/crowd_fund/project.rb, line 43 def to_s "I'm #{@name}'s with a pledge = #{@found_pledge}. " end