Class: Crowdfund::GroupFundRequest
- Inherits:
-
Object
- Object
- Crowdfund::GroupFundRequest
- Defined in:
- lib/crowdfund/groupfundrequest.rb
Instance Attribute Summary collapse
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
Instance Method Summary collapse
- #add_project(project) ⇒ Object
-
#initialize(name) ⇒ GroupFundRequest
constructor
A new instance of GroupFundRequest.
- #load_projects(from_file) ⇒ Object
- #print_funding_status ⇒ Object
- #print_underfunded ⇒ Object
- #request_funding(rounds) ⇒ Object
- #save_underfunded ⇒ Object
- #underfunded ⇒ Object
Constructor Details
#initialize(name) ⇒ GroupFundRequest
Returns a new instance of GroupFundRequest.
11 12 13 14 |
# File 'lib/crowdfund/groupfundrequest.rb', line 11 def initialize(name) @name = name @projects = [] end |
Instance Attribute Details
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
9 10 11 |
# File 'lib/crowdfund/groupfundrequest.rb', line 9 def projects @projects end |
Instance Method Details
#add_project(project) ⇒ Object
16 17 18 |
# File 'lib/crowdfund/groupfundrequest.rb', line 16 def add_project(project) @projects << project end |
#load_projects(from_file) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/crowdfund/groupfundrequest.rb', line 20 def load_projects(from_file) CSV.foreach(from_file) do |row| project = Project.new(row[0],Integer(row[1]),Integer(row[2])) add_project(project) end end |
#print_funding_status ⇒ Object
48 49 50 51 52 53 |
# File 'lib/crowdfund/groupfundrequest.rb', line 48 def print_funding_status puts "\nCurrent Funding of All Projects: " @projects.sort.each { |project| puts "#{project.name} funding: $#{project.funding} of $#{project.goal} "} fully_funded, underfunded = @projects.partition { |project| project.fully_funded? } puts "\nFully Funded Projects: #{fully_funded.size}\nUnderfunded Projects: #{underfunded.size}" end |
#print_underfunded ⇒ Object
59 60 61 |
# File 'lib/crowdfund/groupfundrequest.rb', line 59 def print_underfunded underfunded.each { |project| puts "#{project.name} still needs $#{project.funds_needed}."} end |
#request_funding(rounds) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crowdfund/groupfundrequest.rb', line 27 def request_funding(rounds) puts "\nThere are #{@projects.count} projects in #{@name}:" puts @projects puts "\nThere are #{PledgePool::PLEDGES.count} possible pledge amounts:" PledgePool::PLEDGES.each { |pledge| puts "A #{pledge.name} pledge is worth $#{pledge.amount}" } n = 0 1.upto(rounds) do n += 1 puts "\n Round #{n}:" @projects.each { |project| puts "The funding goal of #{project.name} is $#{project.goal}." } @projects.each { |project| FundingRound.do_round(project) if project.fully_funded? puts "#{project.name} is FULLY FUNDED. (Currently $#{project.funding} toward the goal of $#{project.goal}.)\n" else puts "#{project.name} still needs funds. (Currently $#{project.funding} toward the goal of $#{project.goal}.)\n" end } end end |
#save_underfunded ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/crowdfund/groupfundrequest.rb', line 63 def save_underfunded to_file = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "underfunded.txt") File.open(to_file, "w") do |file| file.puts "Projects that still need funds:" underfunded.each do |project| file.puts "#{project.name} still needs $#{project.funds_needed}." end end puts "The list of underfunded projects has been saved in \"underfunded.txt\"." end |
#underfunded ⇒ Object
55 56 57 |
# File 'lib/crowdfund/groupfundrequest.rb', line 55 def underfunded @projects.sort.reject { |project| project.fully_funded? } end |