Class: CrowdFund::FundRequest
- Inherits:
-
Object
- Object
- CrowdFund::FundRequest
- Defined in:
- lib/crowd_fund/fund_request.rb
Instance Method Summary collapse
- #add_project(project_name) ⇒ Object
- #fully_fund_stats(fully_fund_list) ⇒ Object
-
#initialize(title) ⇒ FundRequest
constructor
A new instance of FundRequest.
- #load_projects(file) ⇒ Object
- #print_stats ⇒ Object
- #print_to_hit_target_stats ⇒ Object
- #request_funding(rounds) ⇒ Object
- #save_to_hit_target_stats(output_file) ⇒ Object
- #to_hit_target_entry(project) ⇒ Object
- #total_pledges_given ⇒ Object
- #under_fund_stats(under_fund_list) ⇒ Object
Constructor Details
#initialize(title) ⇒ FundRequest
Returns a new instance of FundRequest.
10 11 12 13 |
# File 'lib/crowd_fund/fund_request.rb', line 10 def initialize(title) @title = title @projects = [] end |
Instance Method Details
#add_project(project_name) ⇒ Object
15 16 17 |
# File 'lib/crowd_fund/fund_request.rb', line 15 def add_project(project_name) @projects << project_name end |
#fully_fund_stats(fully_fund_list) ⇒ Object
38 39 40 41 42 43 |
# 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) ⇒ Object
19 20 21 22 23 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 ⇒ Object
70 71 72 73 74 75 76 |
# 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) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 |
# 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 ⇒ Object
45 46 47 |
# 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) ⇒ Object
49 50 51 52 53 54 |
# 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 |