class FundraisingProgram::Project
Attributes
funding[RW]
name[RW]
pledges_accumulated[R]
target_funding[R]
Public Class Methods
from_csv(line)
click to toggle source
# File lib/fundraising_program/project.rb, line 18 def self.from_csv(line) name, funding, target_funding = line.split(',') Project.new(name, Integer(funding), Integer(target_funding)) end
new( name, funding = 0, target_funding = 1000 )
click to toggle source
# File lib/fundraising_program/project.rb, line 11 def initialize( name, funding = 0, target_funding = 1000 ) @name = name.capitalize @funding = funding @target_funding = target_funding @pledges_accumulated = Hash.new(0) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/fundraising_program/project.rb, line 42 def <=>(other) other.funding_left <=> funding_left end
add_pledge(pledge)
click to toggle source
# File lib/fundraising_program/project.rb, line 46 def add_pledge(pledge) @pledges_accumulated[pledge.name] += pledge.amount end
each_pledge() { |pledge| ... }
click to toggle source
# File lib/fundraising_program/project.rb, line 23 def each_pledge @pledges_accumulated.each do |name, amount| pledge = Pledge.new(name,amount) yield pledge end end
funding_left()
click to toggle source
# File lib/fundraising_program/project.rb, line 34 def funding_left target_funding - total_funds end
name=(new_name)
click to toggle source
# File lib/fundraising_program/project.rb, line 38 def name=(new_name) @name = new_name.capitalize end
pledges_amount()
click to toggle source
# File lib/fundraising_program/project.rb, line 54 def pledges_amount @pledges_accumulated.values.reduce(0, :+) end
to_s()
click to toggle source
# File lib/fundraising_program/project.rb, line 30 def to_s "O projeto #{@name.upcase} tem investimento acumulado de R$ #{@funding} de R$ #{@target_funding} desejados. Faltam R$ #{funding_left} para o objetivo ser alcancado!" end
total_funds()
click to toggle source
# File lib/fundraising_program/project.rb, line 50 def total_funds @funding + pledges_amount end