class CrowdFund::FundRequest
Public Class Methods
new(project_name)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 8 def initialize(project_name) @project_name = project_name @projects = [] end
Public Instance Methods
add_project(project)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 12 def add_project(project) @projects << project end
alter_funding(amount=25, rounds)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 59 def alter_funding(amount=25, rounds) puts "There are #{@projects.size} projects in the queue: " @projects.each do |project| puts project end puts "There are 3 possible pledge amounts:" pledges = PledgePool::PLEDGES pledges.each do |pledge| puts "A #{pledge.name} pledge is worth $#{pledge.amount}." end 1.upto(rounds) do |n| puts "Round #{n}:\n" @projects.each do |project| FundingRound.randomize_funds(project, amount) FundingRound.random_pledge(project) puts project end end end
load_projects(from_file)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 15 def load_projects(from_file) CSV.foreach(from_file) do |row| add_project(Project.new(row[0], row[1].to_i, row[2].to_i)) end end
print_funding_summary(method, to_file="funding_needed.csv")
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 28 def print_funding_summary(method, to_file="funding_needed.csv") funded, not_funded = @projects.partition { |project| project.fully_funded?} messages = [ "\n", "#{funded.size} projects are fully funded.\n", "\n#{not_funded.size} projects are under-funded.\n", "\nProjects needing more funds:\n" ] not_funded.sort { |a, b| b.funding_needed <=> a.funding_needed}.each do |project| messages.push("Project #{project.name} ($#{project.funding_needed} still needed)") end if method == "to_csv" File.open(to_file, "w") do |file| messages.shift file.puts messages end else puts messages end end
print_funds_needs(project)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 25 def print_funds_needs(project) end
print_stats()
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 48 def print_stats print_funding_summary("to_screen") @projects.each do |project| puts "\nProject #{project.name}'s pledges:" project.each_pledge do |pledge| puts "$#{pledge.amount} in #{pledge.name} pledges" end puts "$#{project.total_pledges} in total pledges" end end
save_projects(to_file)
click to toggle source
# File lib/fundraising_project/fundrequest.rb, line 20 def save_projects(to_file) File.open(to_file, "w") do |file| file.puts end end