class CrowdFund::FundRequest

Public Class Methods

new(title) click to toggle source
# File lib/crowdfund/fundrequest.rb, line 9
def initialize(title)
        @title= title
        @projects= []
end

Public Instance Methods

add_project(name) click to toggle source
# File lib/crowdfund/fundrequest.rb, line 14
def add_project(name)
        @projects << name
end
load_project(from_file='projects.csv') click to toggle source
# File lib/crowdfund/fundrequest.rb, line 18
def load_project(from_file='projects.csv')
        CSV.foreach(from_file).each do |row|
                project = Project.new(row[0], row[1].to_i, row[2].to_i)
                add_project(project)
        end
end
pledge_contributions(project) click to toggle source
# File lib/crowdfund/fundrequest.rb, line 25
def pledge_contributions(project)
        formatted_name= project.name.ljust(20, '.')
        puts "#{formatted_name} #{project.funding_needed}"
end
print_stats() click to toggle source
request_funding(rounds) click to toggle source
# File lib/crowdfund/fundrequest.rb, line 77
def request_funding(rounds)
        puts "There are #{@projects.size} projects:"
        @projects.each do |project|
                puts project
        end
        pledges= Pledge::PLEDGES
        puts "There are #{pledges.size} possible pledge amounts:\n"
        pledges.each do |pledge|
                puts "A #{pledge.level} pledge is worth $#{pledge.amount}."
        end
        1.upto(rounds).each do |round|
                puts "\n Round #{round}:"
                @projects.each do |project|
                        FundingRound.donations_made(project)
                        puts project
                end
        end  
end
save_pledge_contributions(to_file= 'funding_needed.txt') click to toggle source
# File lib/crowdfund/fundrequest.rb, line 30
def save_pledge_contributions(to_file= 'funding_needed.txt')
        File.open(to_file, "w") do |file|
                file.puts "#{@title} still needing funding:"
                @projects.sort.each do |project|
                        file.puts pledge_contributions(project)
                end
        end
end
total_funds() click to toggle source
# File lib/crowdfund/fundrequest.rb, line 39
def total_funds
        @projects.reduce(0) {|sum, p| sum + p.funds}
end