class FundRaise::Project
Attributes
current_funding[R]
name[RW]
target_funding[R]
Public Class Methods
from_csv(string)
click to toggle source
# File lib/fund_raise/project.rb, line 45 def self.from_csv(string) name, target, funding = string.split(',') Project.new(name, Integer(target), Integer(funding)) end
new(name, target=1000, funding=0)
click to toggle source
# File lib/fund_raise/project.rb, line 11 def initialize (name, target=1000, funding=0) @name = name @current_funding = funding @target_funding = target @pledges = Hash.new(0) end
Public Instance Methods
<=>(other_project)
click to toggle source
# File lib/fund_raise/project.rb, line 41 def <=>(other_project) funding_left <=> other_project.funding_left end
each_given_pledge() { |pledge| ... }
click to toggle source
# File lib/fund_raise/project.rb, line 29 def each_given_pledge @pledges.each do |name, amount| pledge = Pledge.new(name, amount) yield pledge end end
pledge_received(pledge)
click to toggle source
# File lib/fund_raise/project.rb, line 22 def pledge_received(pledge) @pledges[pledge.name] += pledge.amount add_funds(pledge.amount, true) puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.amount}." puts "#{@name}'s pledges: #{@pledges}" end
time()
click to toggle source
# File lib/fund_raise/project.rb, line 36 def time current_time = Time.new current_time.strftime("%A, %B %d, %Y") end
to_csv()
click to toggle source
# File lib/fund_raise/project.rb, line 50 def to_csv "#{@name}, #{@target_funding}, #{@current_funding}" end
to_s()
click to toggle source
# File lib/fund_raise/project.rb, line 54 def to_s "#{@name} has $#{@current_funding} in funding towards a goal of $#{@target_funding}." end
total_pledge_points()
click to toggle source
# File lib/fund_raise/project.rb, line 18 def total_pledge_points @pledges.values.reduce(0, :+) end