fund_raise_abr 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README +1 -0
- data/bin/crowd_fund.rb~ +32 -0
- data/bin/fund_raise +37 -0
- data/bin/fund_raise.rb~ +32 -0
- data/bin/fund_raise~ +37 -0
- data/bin/project.csv +3 -0
- data/bin/project.csv~ +3 -0
- data/bin/underfunded_project +6 -0
- data/lib/fund_raise/die.rb +17 -0
- data/lib/fund_raise/fund_request.rb +106 -0
- data/lib/fund_raise/fund_request.rb~ +105 -0
- data/lib/fund_raise/fundable.rb +21 -0
- data/lib/fund_raise/funding_round.rb +22 -0
- data/lib/fund_raise/funding_round.rb~ +22 -0
- data/lib/fund_raise/grant_project.rb +21 -0
- data/lib/fund_raise/grant_project.rb~ +21 -0
- data/lib/fund_raise/match_project.rb +33 -0
- data/lib/fund_raise/match_project.rb~ +33 -0
- data/lib/fund_raise/pledge_pool.rb +27 -0
- data/lib/fund_raise/project.rb +100 -0
- data/lib/fund_raise/project.rb~ +100 -0
- data/lib/fund_request.rb~ +104 -0
- data/lib/funding_round.rb~ +22 -0
- data/lib/grant_project.rb~ +21 -0
- data/lib/match_project.rb~ +33 -0
- data/lib/project.rb~ +100 -0
- data/spec/fund_raise/fund_request_spec.rb +38 -0
- data/spec/fund_raise/fund_request_spec.rb~ +38 -0
- data/spec/fund_raise/project_spec.rb +51 -0
- data/spec/fund_raise/project_spec.rb~ +51 -0
- data/spec/fund_request_spec.rb~ +38 -0
- data/spec/project_spec.rb~ +51 -0
- metadata +98 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative 'fund_request'
|
4
|
+
require_relative 'die'
|
5
|
+
require_relative 'project'
|
6
|
+
require_relative '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 '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 '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
|
data/lib/project.rb~
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative 'pledge_pool'
|
4
|
+
require_relative '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,38 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative '../../lib/fund_raise/project'
|
4
|
+
require_relative '../../lib/fund_raise/fund_request'
|
5
|
+
require_relative '../../lib/fund_raise/die'
|
6
|
+
|
7
|
+
describe FundRequest do
|
8
|
+
|
9
|
+
before do
|
10
|
+
$stdout = StringIO.new
|
11
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
12
|
+
@initial_funding = 150
|
13
|
+
@target = 3000
|
14
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
15
|
+
@fundrequest.add_project(@project)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "rolled die" do
|
19
|
+
it "rolled an even number" do
|
20
|
+
allow_any_instance_of(Die).to receive(:number).and_return(2)
|
21
|
+
#Die.any_instance.stub(:roll).and_return(2)
|
22
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
23
|
+
@fundrequest.add_project(@project)
|
24
|
+
@fundrequest.request_funding(1)
|
25
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "rolled an odd number" do
|
29
|
+
allow_any_instance_of(Die).to receive(:number).and_return(3)
|
30
|
+
#Die.any_instance.stub(:roll).and_return(3)
|
31
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
32
|
+
@fundrequest.add_project(@project)
|
33
|
+
@fundrequest.request_funding(1)
|
34
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative '../lib/fund_raise/project'
|
4
|
+
require_relative '../lib/fund_raise/fund_request'
|
5
|
+
require_relative '../lib/fund_raise/die'
|
6
|
+
|
7
|
+
describe FundRequest do
|
8
|
+
|
9
|
+
before do
|
10
|
+
$stdout = StringIO.new
|
11
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
12
|
+
@initial_funding = 150
|
13
|
+
@target = 3000
|
14
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
15
|
+
@fundrequest.add_project(@project)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "rolled die" do
|
19
|
+
it "rolled an even number" do
|
20
|
+
allow_any_instance_of(Die).to receive(:number).and_return(2)
|
21
|
+
#Die.any_instance.stub(:roll).and_return(2)
|
22
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
23
|
+
@fundrequest.add_project(@project)
|
24
|
+
@fundrequest.request_funding(1)
|
25
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "rolled an odd number" do
|
29
|
+
allow_any_instance_of(Die).to receive(:number).and_return(3)
|
30
|
+
#Die.any_instance.stub(:roll).and_return(3)
|
31
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
32
|
+
@fundrequest.add_project(@project)
|
33
|
+
@fundrequest.request_funding(1)
|
34
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative '../../lib/fund_raise/project'
|
4
|
+
|
5
|
+
describe Project do
|
6
|
+
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@initial_funding = 150
|
10
|
+
@target = 3000
|
11
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has an initial default funding of 0" do
|
15
|
+
@project = Project.new("Project LMN", @target)
|
16
|
+
expect(@project.current_funding).to eq(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "increased funds by 25 when funds are added" do
|
20
|
+
@project.add_funds
|
21
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "decreased funds by 15 when funds are removed" do
|
25
|
+
@project.remove_funds
|
26
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "shows funding outstanding" do
|
30
|
+
@project.add_funds(50)
|
31
|
+
expect(@project.needed_funding).to eq(@target - @initial_funding - 50)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has an initial target amount" do
|
35
|
+
@project = Project.new("Project LMN")
|
36
|
+
expect(@project.target_funding).should_not eq(0)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "project is fully funded" do
|
40
|
+
@project.remove_funds(@initial_funding)
|
41
|
+
@project.add_funds(@target)
|
42
|
+
expect(@project.fully_funded?).to eq(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "project is not fully funded" do
|
46
|
+
@project.remove_funds(@initial_funding)
|
47
|
+
@project.add_funds(@target-1)
|
48
|
+
expect(@project.fully_funded?).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative '../lib/fund_raise/project'
|
4
|
+
|
5
|
+
describe Project do
|
6
|
+
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@initial_funding = 150
|
10
|
+
@target = 3000
|
11
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has an initial default funding of 0" do
|
15
|
+
@project = Project.new("Project LMN", @target)
|
16
|
+
expect(@project.current_funding).to eq(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "increased funds by 25 when funds are added" do
|
20
|
+
@project.add_funds
|
21
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "decreased funds by 15 when funds are removed" do
|
25
|
+
@project.remove_funds
|
26
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "shows funding outstanding" do
|
30
|
+
@project.add_funds(50)
|
31
|
+
expect(@project.needed_funding).to eq(@target - @initial_funding - 50)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has an initial target amount" do
|
35
|
+
@project = Project.new("Project LMN")
|
36
|
+
expect(@project.target_funding).should_not eq(0)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "project is fully funded" do
|
40
|
+
@project.remove_funds(@initial_funding)
|
41
|
+
@project.add_funds(@target)
|
42
|
+
expect(@project.fully_funded?).to eq(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "project is not fully funded" do
|
46
|
+
@project.remove_funds(@initial_funding)
|
47
|
+
@project.add_funds(@target-1)
|
48
|
+
expect(@project.fully_funded?).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative 'project'
|
4
|
+
require_relative 'fund_request'
|
5
|
+
require_relative 'die'
|
6
|
+
|
7
|
+
describe FundRequest do
|
8
|
+
|
9
|
+
before do
|
10
|
+
$stdout = StringIO.new
|
11
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
12
|
+
@initial_funding = 150
|
13
|
+
@target = 3000
|
14
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
15
|
+
@fundrequest.add_project(@project)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "rolled die" do
|
19
|
+
it "rolled an even number" do
|
20
|
+
allow_any_instance_of(Die).to receive(:number).and_return(2)
|
21
|
+
#Die.any_instance.stub(:roll).and_return(2)
|
22
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
23
|
+
@fundrequest.add_project(@project)
|
24
|
+
@fundrequest.request_funding(1)
|
25
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "rolled an odd number" do
|
29
|
+
allow_any_instance_of(Die).to receive(:number).and_return(3)
|
30
|
+
#Die.any_instance.stub(:roll).and_return(3)
|
31
|
+
@fundrequest = FundRequest.new("My Friendly Start-up Projects")
|
32
|
+
@fundrequest.add_project(@project)
|
33
|
+
@fundrequest.request_funding(1)
|
34
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module FundRaise
|
2
|
+
|
3
|
+
require_relative 'project'
|
4
|
+
|
5
|
+
describe Project do
|
6
|
+
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@initial_funding = 150
|
10
|
+
@target = 3000
|
11
|
+
@project = Project.new("Project LMN", @target, @initial_funding)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has an initial default funding of 0" do
|
15
|
+
@project = Project.new("Project LMN", @target)
|
16
|
+
expect(@project.current_funding).to eq(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "increased funds by 25 when funds are added" do
|
20
|
+
@project.add_funds
|
21
|
+
expect(@project.current_funding).to eq(@initial_funding + 25)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "decreased funds by 15 when funds are removed" do
|
25
|
+
@project.remove_funds
|
26
|
+
expect(@project.current_funding).to eq(@initial_funding - 15)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "shows funding outstanding" do
|
30
|
+
@project.add_funds(50)
|
31
|
+
expect(@project.needed_funding).to eq(@target - @initial_funding - 50)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has an initial target amount" do
|
35
|
+
@project = Project.new("Project LMN")
|
36
|
+
expect(@project.target_funding).should_not eq(0)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "project is fully funded" do
|
40
|
+
@project.remove_funds(@initial_funding)
|
41
|
+
@project.add_funds(@target)
|
42
|
+
expect(@project.fully_funded?).to eq(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "project is not fully funded" do
|
46
|
+
@project.remove_funds(@initial_funding)
|
47
|
+
@project.add_funds(@target-1)
|
48
|
+
expect(@project.fully_funded?).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|