class CrowdFund::FundRequest
Public Class Methods
new(title)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 10 def initialize(title) @title = title @projects = [] end
Public Instance Methods
add_project(project_name)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 15 def add_project(project_name) @projects << project_name end
fully_fund_stats(fully_fund_list)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 38 def fully_fund_stats(fully_fund_list) puts "\n#{fully_fund_list.size} fully fund projects:" fully_fund_list.each do |project| puts "#{project.name.ljust(10, '.')} (#{project.amount})" end end
load_projects(file)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 19 def load_projects(file) CSV.foreach(file) do |row| add_project(Project.new(row[0], row[2].to_i, row[1].to_i)) end end
print_stats()
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 56 def print_stats puts "\nAfter all rounds of funds:" puts "\n#{total_pledges_given} pledges given." @projects.each do |project| puts "\nProject #{project.name} total pledges:" project.each_pledge_received do |pledge| puts "$#{pledge.value} on #{pledge.name} pledges." end end fully_fund, under_fund = @projects.partition(&:full?) fully_fund_stats(fully_fund) under_fund_stats(under_fund) end
print_to_hit_target_stats()
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 70 def print_to_hit_target_stats sorted_projects = @projects.reject(&:full?) puts "\nList of projects that still need contributions:" sorted_projects.sort.each do |project| puts to_hit_target_entry(project) end end
request_funding(rounds)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 78 def request_funding(rounds) PledgePool.list @projects.each do |project| puts project end 1.upto(rounds) do |round| puts "\nFunding round number #{round}:" @projects.each do |project| FundingRound.round_of_funds(project) puts project end end end
save_to_hit_target_stats(output_file)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 25 def save_to_hit_target_stats(output_file) under_fund_projects = @projects.reject(&:full?) File.open(output_file, "w") do |file| under_fund_projects.sort.each do |project| file.puts to_hit_target_entry(project) end end end
to_hit_target_entry(project)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 34 def to_hit_target_entry(project) "#{project.name.ljust(50, '.')} (#{project.total_to_fund} to hit target)" end
total_pledges_given()
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 45 def total_pledges_given @projects.reduce(0) { |pledges, project| pledges + project.total_pledges } end
under_fund_stats(under_fund_list)
click to toggle source
# File lib/crowd_fund/fund_request.rb, line 49 def under_fund_stats(under_fund_list) puts "\n#{under_fund_list.size} under fund projects:" under_fund_list.each do |project| puts "#{project.name.ljust(10, '.')} (#{project.amount})" end end