class Crowdfund::Funding
Attributes
title[R]
Public Class Methods
new(title)
click to toggle source
# File lib/crowdfund/funding.rb, line 9 def initialize(title) @title = title @projects = [] end
Public Instance Methods
add_project(a_project)
click to toggle source
# File lib/crowdfund/funding.rb, line 21 def add_project(a_project) @projects << a_project puts "#{a_project.name} was added to #{@title}." end
fund_fun(campaigns)
click to toggle source
# File lib/crowdfund/funding.rb, line 26 def fund_fun(campaigns) @projects.each do |project| puts project end 1.upto(campaigns) do |campaign| puts "\nCampaign: #{campaign}:" @projects.each do |project| FundingRound.spend_or_receive(project) end end end
funding_partition()
click to toggle source
# File lib/crowdfund/funding.rb, line 47 def funding_partition @fully_funded, @under_funded = @projects.partition {|project| project.fully_funded?} end
funding_status(project)
click to toggle source
# File lib/crowdfund/funding.rb, line 51 def funding_status(project) formatted_name = project.name.ljust(20,' ') "#{formatted_name} \tCurrent Funds: $#{project.funding_pledged} \tStill to Raise: $#{project.funds_still_needed}" end
load_projects(from_file)
click to toggle source
# File lib/crowdfund/funding.rb, line 14 def load_projects(from_file) CSV.foreach(from_file) do |row| project = Project.new(row[0], row[1].to_i, row[2].to_i) add_project(project) end end
print_stats()
click to toggle source
# File lib/crowdfund/funding.rb, line 68 def print_stats puts "\n#{@title} Statistics:" funding_partition puts "\n#{@fully_funded.size} fully funded projects:" puts "\n#{@under_funded.size} under funded projects:" puts "\nPrioritized Projects:" sorted_projects = @under_funded.sort sorted_projects.each do |project| puts funding_status(project) end @projects.sort.each do |project| puts "\nProject #{project.name}'s pledges:" project.each_pledge_level do |pledge| puts "#{pledge.amount} in #{pledge.name} pledges" end end end
request_funding(campaigns)
click to toggle source
# File lib/crowdfund/funding.rb, line 39 def request_funding(campaigns) fund_fun(campaigns) puts "\n\nProjects:" @projects.each do |project| puts project end end
save_under_funded_projects(to_file = "needs_funds.txt")
click to toggle source
# File lib/crowdfund/funding.rb, line 56 def save_under_funded_projects(to_file = "needs_funds.txt") funding_partition sorted_projects = @under_funded.sort File.open(to_file, "w") do |file| file.puts "\n#{@under_funded.size} #{@title} projects needing funds:" sorted_projects.each do |project| file.puts funding_status(project) end end end