Class: Crowdfunder::FundRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/crowdfunder/fundrequest.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ FundRequest

Returns a new instance of FundRequest.



9
10
11
12
# File 'lib/crowdfunder/fundrequest.rb', line 9

def initialize(name)
  @name = name
  @projects = []
end

Instance Method Details

#add_project(project) ⇒ Object



35
36
37
# File 'lib/crowdfunder/fundrequest.rb', line 35

def add_project(project)
  @projects << project
end

#load_projects(from_file) ⇒ Object



14
15
16
17
18
19
# File 'lib/crowdfunder/fundrequest.rb', line 14

def load_projects(from_file)
  CSV.foreach(from_file) do |row|
    project = Project.new(row[0], row[1].to_i)
    add_project(project)
  end
end


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/crowdfunder/fundrequest.rb', line 71

def print_stats
  full_funded,  under_funded = @projects.partition do |project|
                                project.fully_funded?
                              end

  puts "\n#{full_funded.size} Fully-Funded Projects:"

  full_funded.sort.each do |project|
    puts report_format(project)
  end

  puts "\n#{under_funded.size} Under-Funded Projects:"

  under_funded.sort.each do |project|
    puts report_format(project)
  end

  puts "\nList of Pending Projects for Funding"
  sorted_projects =  under_funded.sort do |a, b|
    b.total_funding_outstanding <=> a.total_funding_outstanding
  end

  sorted_projects.each do |project|
    puts "#{project.name} requires #{project.total_funding_outstanding}"
  end

  @projects.each do |project|
    puts "\n#{project.name}'s pledges:"
    project.each_pledge_received do |pledge|
      puts "#{pledge.amount} in #{pledge.name} pledges"
    end
    puts "#{project.pledged_funds} in total pledges"
  end
end

#projects_for_contributionObject



65
66
67
68
69
# File 'lib/crowdfunder/fundrequest.rb', line 65

def projects_for_contribution
  @projects.under_funded do |project|
    puts project
  end
end

#report_format(project) ⇒ Object



30
31
32
# File 'lib/crowdfunder/fundrequest.rb', line 30

def report_format(project)
  "#{project.name.ljust(30, '.')} #{project.total_funds}"
end

#request_funding(rounds) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/crowdfunder/fundrequest.rb', line 39

def request_funding(rounds)
  puts "There are #{@projects.size} projects in #{@name}:"

  @projects.each do |project|
    puts project
  end

  pledges = PledgePool::PLEDGES

  puts "\nThere are #{pledges.size} possible pledge amounts:"

  pledges.each do |pledge|
    puts "\tA #{pledge.name} is worth #{pledge.amount}."
  end

  1.upto(rounds) do |count|
    puts "\nRound #{count}:"
    puts "*" * 9
    @projects.each do |project|
      puts "\n"
      FundingRound.one_round(project)
      puts project
    end
  end
end

#save_report_file(to_file = "project_report.txt") ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/crowdfunder/fundrequest.rb', line 21

def save_report_file(to_file="project_report.txt")
  File.open(to_file, 'w') do |file|
    file.puts "#{@name} Funding Report"
    @projects.sort.each do |project|
      file.puts report_format(project)
    end
  end
end