class CrowdFund::FundRequest
Attributes
title[R]
Public Class Methods
new(title)
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 12 def initialize (title) @title = title @projects = [] end
Public Instance Methods
add_project(new_project)
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 39 def add_project(new_project) @projects.push(new_project) end
high_funding_amount(project)
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 26 def high_funding_amount(project) formatted_name = project.name.ljust(20, '.') puts "#{formatted_name} $#{project.total_funding_outstanding}" end
load_funding(from_file)
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 31 def load_funding(from_file) CSV.foreach(from_file) do |row| project = Project.new(row[0], row[1].to_i) add_project(project) end end
print_stats()
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 62 def print_stats puts "\n#{@title}'s' status:" fully_funded, under_funded = @projects.partition { |project| project.fully_funded? } puts "\nFully_funded:" puts fully_funded.sort puts "\nUnder_funded:" puts under_funded.sort puts "\n#{@title} fund:" @projects.sort.each do |project| puts high_funding_amount(project) @projects.sort.each do |project| puts "\n#{project.name}'s pledges:" project.each_pledge do |pledge| puts "$#{pledge.amount} in #{pledge.name} pledges" end puts "$#{project.pledges} grand total pledge" end end end
request_funding(rounds)
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 43 def request_funding(rounds) puts "There are #{@projects.size} projects that you could fund." puts @projects pledge = PledgePool::PLEDGES puts "There are #{pledge.size} possible pledge amounts:" pledge.each do |pledge| puts "A #{pledge.name} pledge is worth $#{pledge.amount}." end 1.upto(rounds) do |round| puts "\n Funding Round #{round}:" @projects.each do |project| FundingRound.round_funds(project) end end def print_stats puts "\n#{@title}'s' status:" fully_funded, under_funded = @projects.partition { |project| project.fully_funded? } puts "\nFully_funded:" puts fully_funded.sort puts "\nUnder_funded:" puts under_funded.sort puts "\n#{@title} fund:" @projects.sort.each do |project| puts high_funding_amount(project) @projects.sort.each do |project| puts "\n#{project.name}'s pledges:" project.each_pledge do |pledge| puts "$#{pledge.amount} in #{pledge.name} pledges" end puts "$#{project.pledges} grand total pledge" end end end end
save_fund_amount(to_file="fund_amount.txt")
click to toggle source
# File lib/crowd_fund/fundrequest.rb, line 17 def save_fund_amount(to_file="fund_amount.txt") File.open(to_file, 'w') do |file| file.puts "#{title} total funds:" @projects.sort.each do |project| puts high_funding_amount(project) end end end