class FundRaise::FundRequest
Attributes
name[RW]
projects_ar[R]
Public Class Methods
new(mylistname)
click to toggle source
# File lib/fund_raise/fund_request.rb, line 12 def initialize (mylistname) @name = mylistname @projects_ar = [] end
Public Instance Methods
add_project(project)
click to toggle source
# File lib/fund_raise/fund_request.rb, line 17 def add_project(project) @projects_ar.push(project) end
load_projects(from_file)
click to toggle source
# File lib/fund_raise/fund_request.rb, line 21 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/fund_raise/fund_request.rb, line 65 def print_stats puts "\n#{@name}'s funding:" puts "$#{total_pledges} in total pledges." @projects_ar.sort.each do |p| puts "\n#{p.name}'s pledges:" p.each_given_pledge do |t| puts "$#{t.amount} in #{t.name} pledges." end end fully, not_fully = @projects_ar.partition { |project| project.fully_funded? } puts "\nThese projects are fully funded:" fully.sort.each do |p| puts "#{p.name}" end puts "\n#{not_fully.size} projects are not fully funded:" not_fully.sort.each do |p| puts "#{p.name} $#{p.current_funding}" end puts "\n#{not_fully.size} projects need your help:" not_fully.sort.each do |p| formatted_name = p.name.ljust(20, '.') puts "#{formatted_name} $#{p.funding_left} funds needed" end end
request_funding(rounds)
click to toggle source
# File lib/fund_raise/fund_request.rb, line 44 def request_funding(rounds) PledgePool::print_pledges_available puts "\nProject List #{@name}:" puts @projects_ar.sort 1.upto(rounds) do |round| puts "\nRound #{round}:" @projects_ar.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/fund_raise/fund_request.rb, line 27 def save_underfunded_projects(to_file="underfunded_projects.txt") File.open(to_file, "w") do |file| file.puts "#{@name} Under-funded projects:" @projects_ar.sort.each do |p| if !p.fully_funded? file.puts underfunded_entry(p) end end end end
to_s()
click to toggle source
# File lib/fund_raise/fund_request.rb, line 96 def to_s "There are #{@projects_ar.size} projects in #{@name}." end
total_pledges()
click to toggle source
# File lib/fund_raise/fund_request.rb, line 59 def total_pledges @projects_ar.reduce(0) do |sum, project| sum + project.total_pledge_points end end
underfunded_entry(project)
click to toggle source
# File lib/fund_raise/fund_request.rb, line 39 def underfunded_entry(project) formatted_name = project.name.ljust(20, '.') "#{formatted_name} $#{project.funding_left} needed" end