class Fundraise::FundRequest
Attributes
name[RW]
projects[R]
Public Class Methods
new(startup)
click to toggle source
# File lib/fundraise/fund_request.rb, line 12 def initialize (startup) @name = startup @projects = [] end
Public Instance Methods
add_project(project)
click to toggle source
# File lib/fundraise/fund_request.rb, line 33 def add_project(project) @projects << project end
load_projects(from_file)
click to toggle source
# File lib/fundraise/fund_request.rb, line 38 def load_projects(from_file) File.readlines(from_file).each do |line| add_project(Project.from_csv(line)) end end
print_stats()
click to toggle source
# File lib/fundraise/fund_request.rb, line 68 def print_stats puts "\n#{@name}'s Stats:" puts "$#{total_pledges} in total pledges." @projects.sort.each do |p| puts "\n#{p.name}'s pledges:" p.each_pledge_received do |pledge| puts "$#{pledge.amount} in #{pledge.name} pledges." end puts "$#{p.pledge_money} in total pledges" end fully_funded, not_fully_funded = @projects.partition { |p| p.fully_funded? } puts "\n#{fully_funded.size} projects are fully funded:" fully_funded.sort.each do |p| puts "#{p.name}" end puts "\n#{not_fully_funded.size} projects are under funded:" not_fully_funded.sort.each do |p| puts "#{p.name} $#{p.current_funding}" end puts "\n#{not_fully_funded.size} projects still need your help:" not_fully_funded.sort.each do |p| formatted_name = p.name.ljust(20, '.') puts "#{formatted_name} $#{p.funding_needed} funds needed" end end
request_funding(rounds)
click to toggle source
# File lib/fundraise/fund_request.rb, line 44 def request_funding(rounds) PledgePool::print_pledges_available puts "\nProject List #{@name}:" 1.upto(rounds) do |round| puts "\nRound #{round}:" @projects.each do |project| puts project FundingRound.one_round(project) puts "#{project}\n\n" end end end
save_underfunded_projects(to_file="underfunded_projects.txt")
click to toggle source
# File lib/fundraise/fund_request.rb, line 22 def save_underfunded_projects(to_file="underfunded_projects.txt") File.open(to_file, "w") do |file| file.puts "#{@name} Under-funded Projects:" @projects.sort.each do |project| if !project.fully_funded? file.puts underfunded_project_entry(project) end end end end
to_s()
click to toggle source
# File lib/fundraise/fund_request.rb, line 58 def to_s "There are #{@projects.size} in #{@name}." end
total_pledges()
click to toggle source
# File lib/fundraise/fund_request.rb, line 62 def total_pledges @projects.reduce(0) do |sum, project| sum + project.pledge_money end end
underfunded_project_entry(project)
click to toggle source
# File lib/fundraise/fund_request.rb, line 17 def underfunded_project_entry(project) formatted_name = project.name.ljust(20, '.') "#{formatted_name} #{project.funding_needed} needed" end