fund_raise_abr 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ module FundRaise
2
+
3
+ require_relative '../lib/fund_raise/fund_request'
4
+ require_relative '../lib/fund_raise/die'
5
+ require_relative '../lib/fund_raise/project'
6
+ require_relative '../lib/fund_raise/pledge_pool'
7
+
8
+ module FundingRound
9
+
10
+ def self.one_round(project)
11
+ die_r = Die.new()
12
+ number = die_r.number
13
+ if number.odd?
14
+ project.remove_funds
15
+ else
16
+ project.add_funds
17
+ end
18
+ project.pledge_received(PledgePool.random)
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,21 @@
1
+ module FundRaise
2
+
3
+ require_relative '../../lib/fund_raise/project'
4
+
5
+ class ProjectGrant < Project
6
+
7
+ def initialize (name, target=1000, grant=0)
8
+ super(name, target, grant)
9
+ end
10
+
11
+ def remove_funds(remove_funding=15)
12
+ puts "#{name} is a grant. Funds can not be removed."
13
+ end
14
+
15
+ end
16
+
17
+ if __FILE__ == $0
18
+ new_grant = ProjectGrant.new("", 50)
19
+ puts new_grant.remove_funds
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module FundRaise
2
+
3
+ require_relative '../lib/fund_raise/project'
4
+
5
+ class ProjectGrant < Project
6
+
7
+ def initialize (name, target=1000, grant=0)
8
+ super(name, target, grant)
9
+ end
10
+
11
+ def remove_funds(remove_funding=15)
12
+ puts "#{name} is a grant. Funds can not be removed."
13
+ end
14
+
15
+ end
16
+
17
+ if __FILE__ == $0
18
+ new_grant = ProjectGrant.new("", 50)
19
+ puts new_grant.remove_funds
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module FundRaise
2
+
3
+ require_relative '../../lib/fund_raise/project'
4
+
5
+ class ProjectMatch < Project
6
+
7
+ def initialize (name, target=1000, funding=0)
8
+ super(name, target, funding)
9
+ @halfway_funded = target / 2
10
+ end
11
+
12
+ def add_funds(add_funding=25, pledge=false)
13
+ if match_funds?
14
+ super(add_funding * 2)
15
+ else
16
+ if (@current_funding = add_funding) >= (@target_funding / 2)
17
+ difference = (@current_funding + add_funding) - @halfway_funded
18
+ super(difference * 2)
19
+ end
20
+ end
21
+ end
22
+
23
+ def match_funds?
24
+ @current_funding >= @target_funding/2
25
+ end
26
+
27
+ end
28
+
29
+ if __FILE__ == $0
30
+ new_match = ProjectMatch.new("Park Fund Matchings", 6000, 2000)
31
+ puts new_match.add_funds(4000)
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module FundRaise
2
+
3
+ require_relative '../lib/fund_raise/project'
4
+
5
+ class ProjectMatch < Project
6
+
7
+ def initialize (name, target=1000, funding=0)
8
+ super(name, target, funding)
9
+ @halfway_funded = target / 2
10
+ end
11
+
12
+ def add_funds(add_funding=25, pledge=false)
13
+ if match_funds?
14
+ super(add_funding * 2)
15
+ else
16
+ if (@current_funding = add_funding) >= (@target_funding / 2)
17
+ difference = (@current_funding + add_funding) - @halfway_funded
18
+ super(difference * 2)
19
+ end
20
+ end
21
+ end
22
+
23
+ def match_funds?
24
+ @current_funding >= @target_funding/2
25
+ end
26
+
27
+ end
28
+
29
+ if __FILE__ == $0
30
+ new_match = ProjectMatch.new("Park Fund Matchings", 6000, 2000)
31
+ puts new_match.add_funds(4000)
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ module FundRaise
2
+
3
+ Pledge = Struct.new(:name, :value)
4
+
5
+ module PledgePool
6
+ PLEDGES = [
7
+ Pledge.new(:bronze,50 ),
8
+ Pledge.new(:silver,75 ),
9
+ Pledge.new(:gold,100 ),
10
+ ]
11
+
12
+ def self.random
13
+ PLEDGES.sample
14
+ end
15
+
16
+ def self.print_pledges_available
17
+ puts "There are #{PLEDGES.size} possible pledge amounts:"
18
+ PLEDGES.each do |p|
19
+ puts "\t A #{p.name} pledge is worth #{p.value}."
20
+ end
21
+ end
22
+ end
23
+
24
+ if __FILE__ == $0
25
+ puts PledgePool::PLEDGES
26
+ end
27
+ end
@@ -0,0 +1,100 @@
1
+ module FundRaise
2
+
3
+ require_relative '../../lib/fund_raise/pledge_pool'
4
+ require_relative '../../lib/fund_raise/fundable'
5
+
6
+ class Project
7
+ include Fundable
8
+
9
+ attr_accessor :name
10
+ attr_reader :current_funding, :target_funding
11
+
12
+ def initialize (name, target= 1000, funding=0)
13
+ @name = name
14
+ @current_funding = funding
15
+ @target_funding = target
16
+ @pledges_received = Hash.new(0)
17
+ end
18
+
19
+ def pledge_received(pledge)
20
+ @pledges_received[pledge.name] += pledge.value
21
+ add_funds(pledge.value)
22
+ puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.value}."
23
+ puts "#{@name}'s pledges: #{@pledges_received}"
24
+ end
25
+
26
+ def each_given_pledge
27
+ @pledges_received.each do |name, value|
28
+ pledge = Pledge.new(name, value)
29
+ yield pledge
30
+ end
31
+ end
32
+
33
+ def needed_funding
34
+ @target_funding - @current_funding
35
+ end
36
+
37
+ def self.from_csv(string)
38
+ name, target, funding = string.split(',')
39
+ player = Project.new(name, Integer(target), Integer(funding))
40
+ end
41
+
42
+ def to_csv
43
+ "#{@name}, #{@target_funding}, #{@current_funding}"
44
+ end
45
+
46
+ def pledge_money
47
+ @pledges_received.values.reduce(0, :+)
48
+ end
49
+
50
+ def total_funding
51
+ @current_funding + pledge_money
52
+ end
53
+
54
+ def time
55
+ current_time = Time.new
56
+ current_time.strftime("%A, %B, %d, %Y")
57
+ end
58
+
59
+ def <=>(other_project)
60
+ needed_funding <=> other_project.needed_funding
61
+ end
62
+
63
+ def to_s
64
+ "#{@name} has $#{@current_funding} in funding towards a goal of $#{@target_funding}"
65
+ end
66
+ end
67
+
68
+ if __FILE__ == $0
69
+ project1 = Project.new("Project ABC", 3000, 500)
70
+ project2 = Project.new("Project LMN", 225, 25)
71
+ project3 = Project.new("Project XYZ", 100, 110)
72
+
73
+ projects_ar = [project1, project2]
74
+
75
+ puts "There are #{projects_ar.size} projects in the array:"
76
+ projects_ar.each do |project|
77
+ puts project
78
+ end
79
+ puts project1.remove_funds
80
+ puts project2.add_funds
81
+
82
+ projects_ar.each do |project|
83
+ puts project
84
+ end
85
+
86
+ projects_ar.each do |project|
87
+ if project.current_funding < 90
88
+ puts "DELETE #{project.name}"
89
+ projects_ar.delete(project)
90
+ end
91
+ end
92
+ projects_ar.push(project3)
93
+
94
+ puts "\nThere are #{projects_ar.size} projects in the array."
95
+ projects_ar.each do |project|
96
+ puts project
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,100 @@
1
+ module FundRaise
2
+
3
+ require_relative '../lib/fund_raise/pledge_pool'
4
+ require_relative '../lib/fund_raise/fundable'
5
+
6
+ class Project
7
+ include Fundable
8
+
9
+ attr_accessor :name
10
+ attr_reader :current_funding, :target_funding
11
+
12
+ def initialize (name, target= 1000, funding=0)
13
+ @name = name
14
+ @current_funding = funding
15
+ @target_funding = target
16
+ @pledges_received = Hash.new(0)
17
+ end
18
+
19
+ def pledge_received(pledge)
20
+ @pledges_received[pledge.name] += pledge.value
21
+ add_funds(pledge.value)
22
+ puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.value}."
23
+ puts "#{@name}'s pledges: #{@pledges_received}"
24
+ end
25
+
26
+ def each_given_pledge
27
+ @pledges_received.each do |name, value|
28
+ pledge = Pledge.new(name, value)
29
+ yield pledge
30
+ end
31
+ end
32
+
33
+ def needed_funding
34
+ @target_funding - @current_funding
35
+ end
36
+
37
+ def self.from_csv(string)
38
+ name, target, funding = string.split(',')
39
+ player = Project.new(name, Integer(target), Integer(funding))
40
+ end
41
+
42
+ def to_csv
43
+ "#{@name}, #{@target_funding}, #{@current_funding}"
44
+ end
45
+
46
+ def pledge_money
47
+ @pledges_received.values.reduce(0, :+)
48
+ end
49
+
50
+ def total_funding
51
+ @current_funding + pledge_money
52
+ end
53
+
54
+ def time
55
+ current_time = Time.new
56
+ current_time.strftime("%A, %B, %d, %Y")
57
+ end
58
+
59
+ def <=>(other_project)
60
+ needed_funding <=> other_project.needed_funding
61
+ end
62
+
63
+ def to_s
64
+ "#{@name} has $#{@current_funding} in funding towards a goal of $#{@target_funding}"
65
+ end
66
+ end
67
+
68
+ if __FILE__ == $0
69
+ project1 = Project.new("Project ABC", 3000, 500)
70
+ project2 = Project.new("Project LMN", 225, 25)
71
+ project3 = Project.new("Project XYZ", 100, 110)
72
+
73
+ projects_ar = [project1, project2]
74
+
75
+ puts "There are #{projects_ar.size} projects in the array:"
76
+ projects_ar.each do |project|
77
+ puts project
78
+ end
79
+ puts project1.remove_funds
80
+ puts project2.add_funds
81
+
82
+ projects_ar.each do |project|
83
+ puts project
84
+ end
85
+
86
+ projects_ar.each do |project|
87
+ if project.current_funding < 90
88
+ puts "DELETE #{project.name}"
89
+ projects_ar.delete(project)
90
+ end
91
+ end
92
+ projects_ar.push(project3)
93
+
94
+ puts "\nThere are #{projects_ar.size} projects in the array."
95
+ projects_ar.each do |project|
96
+ puts project
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,104 @@
1
+ module FundRaise
2
+
3
+ require_relative 'project'
4
+ require_relative 'funding_round'
5
+ require_relative 'die'
6
+ require_relative 'pledge_pool'
7
+
8
+ class FundRequest
9
+ attr_accessor :name
10
+ attr_reader :projects_ar
11
+
12
+ def initialize (mylistname)
13
+ @name = mylistname
14
+ @projects_ar = []
15
+ end
16
+
17
+ def add_project(project)
18
+ @projects_ar.push(project)
19
+ end
20
+
21
+ def load_projects(from_file)
22
+ File.readlines(from_file).each do |line|
23
+ add_project(Project.from_csv(line))
24
+ end
25
+ end
26
+
27
+ def request_funding(rounds)
28
+ PledgePool::print_pledges_available
29
+ puts "Project List: #{@name}:"
30
+
31
+ 1.upto(rounds) do |round|
32
+ puts"\nRound #{round}"
33
+ @projects_ar.each do |project|
34
+ puts project
35
+ FundingRound.one_round(project)
36
+ puts "#{project}\n\n"
37
+ end
38
+ end
39
+ end
40
+
41
+ def save_under_funded(to_file="under_funded.txt")
42
+ File.open(to_file, "w") do |file|
43
+ file.puts "#{@name}'s Under-funded projects:"
44
+
45
+ @projects_ar.sort.each do |p|
46
+ file.puts underfunded_entry(p)
47
+ end
48
+ end
49
+ end
50
+
51
+ def underfunded_entry(project)
52
+ formatted_name = project.name.ljust(20, '.')
53
+ "#{formatted_name} $#{project.funding_left} needed"
54
+ end
55
+
56
+ def print_stats
57
+ fully, not_fully = @projects_ar.partition { |project| project.fully_funded? }
58
+
59
+ puts "\n#{@name}'s funding:"
60
+
61
+ @projects_ar.sort.each do |p|
62
+ puts "\n#{p.name}'s total funding is $#{p.total_funding}"
63
+ p.each_given_pledge do |pl|
64
+ puts "#{pl.value} total #{pl.name} points"
65
+ end
66
+ end
67
+
68
+ puts "\nThese projects are fully funded:"
69
+ fully.sort.each do |p|
70
+ puts "#{p.name}"
71
+ end
72
+
73
+ puts "\n#{not_fully.size} projects are not fully funded:"
74
+ not_fully.sort.each do |p|
75
+ puts "#{p.name} ($#{p.current_funding})"
76
+ end
77
+
78
+ puts "\n#{not_fully.size} project(s) still need your help:"
79
+ not_fully.sort.each do |p|
80
+ puts "#{p.name} needs #{p.needed_funding} dollars."
81
+ end
82
+ end
83
+
84
+ def to_s
85
+ "There are #{@projects_ar.size} projects in #{@name}."
86
+ end
87
+ end
88
+
89
+ if __FILE__ == $0
90
+ project1 = Project.new("Project ABC", 3000, 500)
91
+ project2 = Project.new("Project LMN", 225, 25)
92
+ project3 = Project.new("Project XYZ", 100, 110)
93
+
94
+
95
+ my_project = FundRequest.new("VC-Friendly Start-up Projects.")
96
+
97
+ my_project.add_project(project1)
98
+ my_project.add_project(project2)
99
+ my_project.add_project(project3)
100
+
101
+ my_project.request_funding
102
+
103
+ end
104
+ end