fund_list 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 +21 -0
- data/README +19 -0
- data/bin/crowd_fund +32 -0
- data/bin/projects.csv +3 -0
- data/lib/crowd_fund/die.rb +13 -0
- data/lib/crowd_fund/fund_request.rb +98 -0
- data/lib/crowd_fund/fundable.rb +29 -0
- data/lib/crowd_fund/funding_round.rb +21 -0
- data/lib/crowd_fund/grand_project.rb +22 -0
- data/lib/crowd_fund/pledge_pool.rb +22 -0
- data/lib/crowd_fund/printable.rb +7 -0
- data/lib/crowd_fund/project.rb +47 -0
- data/lib/crowd_fund/secure_project.rb +29 -0
- data/spec/crowd_fund/fund_request_spec.rb +77 -0
- data/spec/crowd_fund/grand_project_spec.rb +19 -0
- data/spec/crowd_fund/pledge_pool_spec.rb +45 -0
- data/spec/crowd_fund/project_spec.rb +146 -0
- data/spec/crowd_fund/secure_project_spec.rb +31 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0e34b85125b17c94d82b34cbfe1f05e9da88c04d
|
|
4
|
+
data.tar.gz: 207de0adc2e7f2a1c1e0a25215b9d868e224e02e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2bb37054b620bbbbe4998e9b11b690a3351bfe3cb9ad8bacba551810bad3641a6d1e33a659a31f050a421faac874f0372794a2acf38b620eeefac3e8acffd100
|
|
7
|
+
data.tar.gz: f38a18385afaac470df02bea8fa150bbf461db8c5e5da2d6a8c6ce727f75e79708ddb07a3f5fc9ae4214cc7afbf95e77a3cb0a3315473375435305e97ae532f1
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Victor Alexandre Franco Silva
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
This RubyGem contains a nice-n-easy funding projects simulation, called FundList.
|
|
2
|
+
|
|
3
|
+
The sim runs in command-line, calling just the command crowd_fund (easy as that :0 )
|
|
4
|
+
|
|
5
|
+
You can choose the number of funding rounds and it will display the current stats of the projects.
|
|
6
|
+
|
|
7
|
+
You can also create a '.csv' file to hold projects, with a current amount and a target.
|
|
8
|
+
This file should be put next to the command when calling the sim.
|
|
9
|
+
|
|
10
|
+
File structure:
|
|
11
|
+
|
|
12
|
+
--NAME--|--TARGET--|--AMOUNT-- (This is just for explanatory purpose)
|
|
13
|
+
Project,1000,100
|
|
14
|
+
(The commas must be put into each string of projects, without blankspace.)
|
|
15
|
+
|
|
16
|
+
Have fun on this simulation. If you have any ideas, you can use the code,
|
|
17
|
+
which already is tested, to create a new, different, sim!
|
|
18
|
+
|
|
19
|
+
Good-bye !! =)
|
data/bin/crowd_fund
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative '../lib/crowd_fund/fund_request'
|
|
3
|
+
require_relative '../lib/crowd_fund/grand_project'
|
|
4
|
+
require_relative '../lib/crowd_fund/secure_project'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
list1 = CrowdFund::FundRequest.new("VC_Friendly Start-up Projects")
|
|
8
|
+
default_project_file = File.join(File.dirname(__FILE__), 'projects.csv')
|
|
9
|
+
list1.load_projects(ARGV.shift || default_project_file)
|
|
10
|
+
|
|
11
|
+
grand = CrowdFund::GrandProject.new("grand", 1000, 5000)
|
|
12
|
+
secure = CrowdFund::SecureProject.new("secure", 2000, 20000)
|
|
13
|
+
|
|
14
|
+
list1.add_project(grand)
|
|
15
|
+
list1.add_project(secure)
|
|
16
|
+
|
|
17
|
+
loop do
|
|
18
|
+
puts "\nHow many rounds of funds the projects will have ? (type 'quit' to exit)"
|
|
19
|
+
answer = gets.chomp.downcase
|
|
20
|
+
case answer
|
|
21
|
+
when /^\d+$/
|
|
22
|
+
list1.request_funding(answer.to_i)
|
|
23
|
+
when 'quit', 'exit'
|
|
24
|
+
list1.print_stats
|
|
25
|
+
list1.print_to_hit_target_stats
|
|
26
|
+
break
|
|
27
|
+
else
|
|
28
|
+
puts "\nPlease, choose how many rounds or 'quit'..."
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
list1.save_to_hit_target_stats("under_funded_projects.txt")
|
data/bin/projects.csv
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require_relative 'project'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'funding_round'
|
|
4
|
+
require_relative 'pledge_pool'
|
|
5
|
+
|
|
6
|
+
require 'csv'
|
|
7
|
+
|
|
8
|
+
module CrowdFund
|
|
9
|
+
class FundRequest
|
|
10
|
+
def initialize(title)
|
|
11
|
+
@title = title
|
|
12
|
+
@projects = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_project(project_name)
|
|
16
|
+
@projects << project_name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def load_projects(file)
|
|
20
|
+
CSV.foreach(file) do |row|
|
|
21
|
+
add_project(Project.new(row[0], row[2].to_i, row[1].to_i))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def save_to_hit_target_stats(output_file)
|
|
26
|
+
under_fund_projects = @projects.reject(&:full?)
|
|
27
|
+
File.open(output_file, "w") do |file|
|
|
28
|
+
under_fund_projects.sort.each do |project|
|
|
29
|
+
file.puts to_hit_target_entry(project)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_hit_target_entry(project)
|
|
35
|
+
"#{project.name.ljust(50, '.')} (#{project.total_to_fund} to hit target)"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def fully_fund_stats(fully_fund_list)
|
|
39
|
+
puts "\n#{fully_fund_list.size} fully fund projects:"
|
|
40
|
+
fully_fund_list.each do |project|
|
|
41
|
+
puts "#{project.name.ljust(10, '.')} (#{project.amount})"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def total_pledges_given
|
|
46
|
+
@projects.reduce(0) { |pledges, project| pledges + project.total_pledges }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def under_fund_stats(under_fund_list)
|
|
50
|
+
puts "\n#{under_fund_list.size} under fund projects:"
|
|
51
|
+
under_fund_list.each do |project|
|
|
52
|
+
puts "#{project.name.ljust(10, '.')} (#{project.amount})"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def print_stats
|
|
57
|
+
puts "\nAfter all rounds of funds:"
|
|
58
|
+
puts "\n#{total_pledges_given} pledges given."
|
|
59
|
+
@projects.each do |project|
|
|
60
|
+
puts "\nProject #{project.name} total pledges:"
|
|
61
|
+
project.each_pledge_received do |pledge|
|
|
62
|
+
puts "$#{pledge.value} on #{pledge.name} pledges."
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
fully_fund, under_fund = @projects.partition(&:full?)
|
|
66
|
+
fully_fund_stats(fully_fund)
|
|
67
|
+
under_fund_stats(under_fund)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def print_to_hit_target_stats
|
|
71
|
+
sorted_projects = @projects.reject(&:full?)
|
|
72
|
+
puts "\nList of projects that still need contributions:"
|
|
73
|
+
sorted_projects.sort.each do |project|
|
|
74
|
+
puts to_hit_target_entry(project)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def request_funding(rounds)
|
|
79
|
+
PledgePool.list
|
|
80
|
+
@projects.each do |project|
|
|
81
|
+
puts project
|
|
82
|
+
end
|
|
83
|
+
1.upto(rounds) do |round|
|
|
84
|
+
puts "\nFunding round number #{round}:"
|
|
85
|
+
@projects.each do |project|
|
|
86
|
+
FundingRound.round_of_funds(project)
|
|
87
|
+
puts project
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if __FILE__ == $0
|
|
94
|
+
funding_scenario = Fund_Request.new("first_funding")
|
|
95
|
+
funding_scenario.add_project(Project.new("ProJect", 5000, 10000))
|
|
96
|
+
funding_scenario.request_funding
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module CrowdFund
|
|
2
|
+
module Fundable
|
|
3
|
+
def add(amount_to_add)
|
|
4
|
+
self.amount += amount_to_add
|
|
5
|
+
puts "\n#{name} got more funds."
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def <=>(other)
|
|
9
|
+
other.total_to_fund <=> total_to_fund
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def remove(amount_to_remove)
|
|
13
|
+
self.amount -= amount_to_remove
|
|
14
|
+
puts "\n#{name} lost some funds."
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def stats
|
|
18
|
+
full? ? "Full!" : "Is under funded yet"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def full?
|
|
22
|
+
total_to_fund <= 0
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def total_to_fund
|
|
26
|
+
self.target - self.amount
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'project'
|
|
3
|
+
require_relative 'pledge_pool'
|
|
4
|
+
|
|
5
|
+
module CrowdFund
|
|
6
|
+
module FundingRound
|
|
7
|
+
def self.round_of_funds(project)
|
|
8
|
+
die = Die.new
|
|
9
|
+
case die.roll
|
|
10
|
+
when 5..6
|
|
11
|
+
project.remove(125)
|
|
12
|
+
when 1..2
|
|
13
|
+
project.add(500)
|
|
14
|
+
else
|
|
15
|
+
puts "\n#{project.name} didn't receive funds this time."
|
|
16
|
+
end
|
|
17
|
+
pledge = PledgePool.randomize
|
|
18
|
+
project.receive_pledge(pledge)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative 'project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
class GrandProject < Project
|
|
5
|
+
|
|
6
|
+
def remove(amount_to_remove)
|
|
7
|
+
puts "\n#{@name} does not allow removing $#{amount_to_remove}, because it's a grand project!"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if __FILE__ == $0
|
|
14
|
+
grand = GrandProject.new("foo", 100, 1000)
|
|
15
|
+
grand.add(100)
|
|
16
|
+
grand.add(100)
|
|
17
|
+
grand.add(100)
|
|
18
|
+
puts grand
|
|
19
|
+
grand.remove(200)
|
|
20
|
+
puts grand
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module CrowdFund
|
|
2
|
+
Pledge = Struct.new(:name, :value)
|
|
3
|
+
|
|
4
|
+
module PledgePool
|
|
5
|
+
PLEDGES = [
|
|
6
|
+
Pledge.new(:bronze, 50),
|
|
7
|
+
Pledge.new(:silver, 75),
|
|
8
|
+
Pledge.new(:gold, 100)
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
def self.randomize
|
|
12
|
+
PLEDGES.sample
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.list
|
|
16
|
+
puts "There are #{PLEDGES.size} possible pledge amounts:"
|
|
17
|
+
PLEDGES.each do |pledge|
|
|
18
|
+
puts "A #{pledge.name} pledge is worth $#{pledge.value}."
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require_relative 'pledge_pool'
|
|
2
|
+
require_relative 'fundable'
|
|
3
|
+
require_relative 'printable'
|
|
4
|
+
|
|
5
|
+
module CrowdFund
|
|
6
|
+
class Project
|
|
7
|
+
|
|
8
|
+
include Fundable
|
|
9
|
+
include Printable
|
|
10
|
+
|
|
11
|
+
attr_accessor :name, :amount, :target
|
|
12
|
+
|
|
13
|
+
def initialize(name, amount=0, target=1000)
|
|
14
|
+
@name = name.upcase
|
|
15
|
+
@amount = amount
|
|
16
|
+
@target = target
|
|
17
|
+
@pledges_received = Hash.new(0)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def total_pledges
|
|
21
|
+
@pledges_received.values.reduce(0, :+)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def each_pledge_received
|
|
25
|
+
@pledges_received.each do |name, value|
|
|
26
|
+
yield Pledge.new(name, value)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def receive_pledge(pledge)
|
|
31
|
+
@pledges_received[pledge.name] += pledge.value
|
|
32
|
+
@amount += total_pledges
|
|
33
|
+
puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.value}."
|
|
34
|
+
puts "Project #{@name} pledges: #{@pledges_received}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if __FILE__ == $PROGRAM_NAME
|
|
39
|
+
project1 = Project.new("new_project", 5000, 150000)
|
|
40
|
+
puts project1
|
|
41
|
+
3.times do
|
|
42
|
+
project1.add(4000)
|
|
43
|
+
end
|
|
44
|
+
project1.remove(10000)
|
|
45
|
+
puts project1
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
class SecureProject < Project
|
|
5
|
+
|
|
6
|
+
def halfway?
|
|
7
|
+
@amount == target / 2
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add(amount_to_add)
|
|
11
|
+
if halfway?
|
|
12
|
+
super(total_to_fund)
|
|
13
|
+
puts "\n#{@name} has received a matching fund."
|
|
14
|
+
else
|
|
15
|
+
super(amount_to_add)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __FILE__ == $0
|
|
23
|
+
secure = SecureProject.new("bar", 100, 2000)
|
|
24
|
+
10.times do
|
|
25
|
+
secure.add(100)
|
|
26
|
+
puts secure
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'crowd_fund/fund_request'
|
|
2
|
+
require 'crowd_fund/die'
|
|
3
|
+
require 'crowd_fund/funding_round'
|
|
4
|
+
|
|
5
|
+
module CrowdFund
|
|
6
|
+
describe FundRequest do
|
|
7
|
+
before do
|
|
8
|
+
$stdout = StringIO.new
|
|
9
|
+
@funding_scenario = FundRequest.new("test_funding")
|
|
10
|
+
|
|
11
|
+
@amount = 5000
|
|
12
|
+
@target = 10000
|
|
13
|
+
@amount_to_add = 500
|
|
14
|
+
@amount_to_remove = 125
|
|
15
|
+
@project = Project.new("new_project", @amount, @target)
|
|
16
|
+
|
|
17
|
+
@funding_scenario.add_project(@project)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "formats the entries of to_hit_target projects" do
|
|
21
|
+
string = @funding_scenario.to_hit_target_entry(@project)
|
|
22
|
+
|
|
23
|
+
expect(string).to eq("#{@project.name.ljust(50, '.')} (#{@project.total_to_fund} to hit target)")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "gives a random pledge to a project during a funding turn" do
|
|
27
|
+
@funding_scenario.request_funding(1)
|
|
28
|
+
|
|
29
|
+
expect(@project.total_pledges).not_to be_zero
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "adds funds and pledges when a lower number is rolled" do
|
|
33
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(1)
|
|
34
|
+
|
|
35
|
+
@funding_scenario.request_funding(1)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
expect(@project.amount).to eq(@amount + @amount_to_add + @project.total_pledges)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "removes funds when a higher number is rolled" do
|
|
42
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(5)
|
|
43
|
+
|
|
44
|
+
@funding_scenario.request_funding(1)
|
|
45
|
+
|
|
46
|
+
expect(@project.amount).to eq(@amount + @project.total_pledges - @amount_to_remove)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "skips funding when a medium number is rolled" do
|
|
50
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
|
51
|
+
|
|
52
|
+
@funding_scenario.request_funding(1)
|
|
53
|
+
|
|
54
|
+
expect(@project.amount).to eq(@amount + @project.total_pledges)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "at the end of funding scenario" do
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
@project = Project.new("new_project", @amount, @target)
|
|
61
|
+
@project2 = Project.new("foo_project", 100, 1000)
|
|
62
|
+
|
|
63
|
+
@funding_scenario.add_project(@project)
|
|
64
|
+
@funding_scenario.add_project(@project2)
|
|
65
|
+
|
|
66
|
+
@project.receive_pledge(Pledge.new(:bronze, 50))
|
|
67
|
+
@project2.receive_pledge(Pledge.new(:gold, 100))
|
|
68
|
+
@project.receive_pledge(Pledge.new(:silver, 75))
|
|
69
|
+
@project2.receive_pledge(Pledge.new(:bronze, 50))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "computes the total pledges given to all projects" do
|
|
73
|
+
expect(@funding_scenario.total_pledges_given).to eq(275)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'crowd_fund/grand_project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe GrandProject do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@amount = 100
|
|
8
|
+
$stdout = StringIO.new
|
|
9
|
+
@grand = GrandProject.new("abc", @amount)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "does not allow funds to be removed" do
|
|
13
|
+
@grand.remove(100)
|
|
14
|
+
|
|
15
|
+
expect(@grand.amount).to eq(@amount)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'crowd_fund/pledge_pool'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe Pledge do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@pledge = Pledge.new(:gold, 100)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "has a name attribute" do
|
|
11
|
+
expect(@pledge.name).to eq(:gold)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "has a value attribute" do
|
|
15
|
+
expect(@pledge.value).to eq(100)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe PledgePool do
|
|
19
|
+
|
|
20
|
+
it "has an array with three pledge values" do
|
|
21
|
+
expect(PledgePool::PLEDGES.size).to eq(3)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "has a bronze pledge of value $50" do
|
|
25
|
+
expect(PledgePool::PLEDGES[0]).to eq(Pledge.new(:bronze, 50))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "has a silver pledge of value $75" do
|
|
29
|
+
expect(PledgePool::PLEDGES[1]).to eq(Pledge.new(:silver, 75))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "has a gold pledge of value $100" do
|
|
33
|
+
expect(PledgePool::PLEDGES[2]).to eq(Pledge.new(:gold, 100))
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "receiving a pledge" do
|
|
38
|
+
|
|
39
|
+
it "randomizes a pledge to fund a project" do
|
|
40
|
+
expect(PledgePool::PLEDGES).to include(PledgePool.randomize)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require 'crowd_fund/project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe Project do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@amount_to_add = 200
|
|
8
|
+
@amount_to_remove = 20
|
|
9
|
+
@project = Project.new("new_project", 100, 1000)
|
|
10
|
+
$stdout = StringIO.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "has name in upcase form" do
|
|
14
|
+
expect(@project.name).to eq("NEW_PROJECT")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "has an initial target funding amount" do
|
|
18
|
+
expect(@project.target).to eq(1000)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "computes the total value of each received pledge" do
|
|
22
|
+
@project.receive_pledge(Pledge.new(:bronze, 50))
|
|
23
|
+
@project.receive_pledge(Pledge.new(:bronze, 50))
|
|
24
|
+
@project.receive_pledge(Pledge.new(:gold, 100))
|
|
25
|
+
@project.receive_pledge(Pledge.new(:silver, 75))
|
|
26
|
+
@project.receive_pledge(Pledge.new(:silver, 75))
|
|
27
|
+
|
|
28
|
+
yielded = []
|
|
29
|
+
|
|
30
|
+
@project.each_pledge_received do |pledge|
|
|
31
|
+
yielded << pledge
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
expect(yielded).to eq([
|
|
35
|
+
Pledge.new(:bronze, 100),
|
|
36
|
+
Pledge.new(:gold, 100),
|
|
37
|
+
Pledge.new(:silver, 150)
|
|
38
|
+
])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "computes a total of all received pledges" do
|
|
42
|
+
expect(@project.total_pledges).to eq(0)
|
|
43
|
+
|
|
44
|
+
@project.receive_pledge(Pledge.new(:bronze, 50))
|
|
45
|
+
|
|
46
|
+
expect(@project.total_pledges).to eq(50)
|
|
47
|
+
|
|
48
|
+
@project.receive_pledge(Pledge.new(:silver, 75))
|
|
49
|
+
|
|
50
|
+
expect(@project.total_pledges).to eq(125)
|
|
51
|
+
|
|
52
|
+
@project.receive_pledge(Pledge.new(:gold, 100))
|
|
53
|
+
|
|
54
|
+
expect(@project.total_pledges).to eq(225)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "has a string representation of the project" do
|
|
58
|
+
expect(@project.to_s).to eq("\n#{@project.name} has an amount of #{@project.amount} towards a target of #{@project.target}.\nIt has #{@project.total_to_fund} to reach target (#{@project.stats}).")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "computes the total funding outstanding as the target funding minus the funding amount" do
|
|
62
|
+
expect(@project.total_to_fund).to eq(1000 - 100)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "increases funds by an amount when funds are added" do
|
|
66
|
+
@project.add(@amount_to_add)
|
|
67
|
+
|
|
68
|
+
expect(@project.amount).to eq(300)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "increases funds when pledges are received" do
|
|
72
|
+
@project.receive_pledge(Pledge.new(:bronze, 50))
|
|
73
|
+
|
|
74
|
+
expect(@project.amount).to eq(150)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "decreases funds by an amount when funds are removed" do
|
|
78
|
+
@project.remove(@amount_to_remove)
|
|
79
|
+
|
|
80
|
+
expect(@project.amount).to eq(100 - @amount_to_remove)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "has a default amount and target" do
|
|
84
|
+
before do
|
|
85
|
+
@default_project = Project.new("new_project")
|
|
86
|
+
end
|
|
87
|
+
it "has the default value of zero for funding amount" do
|
|
88
|
+
expect(@default_project.amount).to eq(0)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "has a default value of 1000 for target funding" do
|
|
92
|
+
expect(@project.target).to eq(1000)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context "has reached full funding" do
|
|
97
|
+
before do
|
|
98
|
+
@target = 1000
|
|
99
|
+
@project = Project.new("new_project", @target, @target)
|
|
100
|
+
$stdout = StringIO.new
|
|
101
|
+
end
|
|
102
|
+
it "is full" do
|
|
103
|
+
@project.full?
|
|
104
|
+
|
|
105
|
+
expect(@project).to be_full
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "has a full status" do
|
|
109
|
+
expect(@project.stats).to eq("Full!")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context "has not reached full funding" do
|
|
114
|
+
before do
|
|
115
|
+
@amount = 100
|
|
116
|
+
@target = 1000
|
|
117
|
+
@project = Project.new("new_project", @amount, @target)
|
|
118
|
+
$stdout = StringIO.new
|
|
119
|
+
end
|
|
120
|
+
it "is full" do
|
|
121
|
+
@project.full?
|
|
122
|
+
|
|
123
|
+
expect(@project).not_to be_full
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "has a under funded status" do
|
|
127
|
+
expect(@project.stats).to eq("Is under funded yet")
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "in a collection of projects" do
|
|
132
|
+
|
|
133
|
+
before do
|
|
134
|
+
@project1 = Project.new("abc", 6000, 10000)
|
|
135
|
+
@project2 = Project.new("lmn", 4000, 10000)
|
|
136
|
+
@project3 = Project.new("xyz", 1000, 10000)
|
|
137
|
+
|
|
138
|
+
@projects = [@project1, @project2, @project3]
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "sorts the list in decreased outstanding amount order" do
|
|
142
|
+
expect(@projects.sort).to eq([@project3, @project2, @project1])
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'crowd_fund/secure_project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe SecureProject do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
$stdout = StringIO.new
|
|
8
|
+
@amount = 100
|
|
9
|
+
@amount_to_add = 100
|
|
10
|
+
@secure = SecureProject.new("abc", @amount, 1000)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "does not match funds when the project is halfway funded" do
|
|
14
|
+
3.times {@secure.add(@amount_to_add)}
|
|
15
|
+
|
|
16
|
+
expect(@secure.halfway?).to be_falsey
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "matches funds when the project is halfway towards the target" do
|
|
20
|
+
4.times {@secure.add(@amount_to_add)}
|
|
21
|
+
|
|
22
|
+
expect(@secure.halfway?).to be_truthy
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "receives a matching fund when it's halfway towards the target" do
|
|
26
|
+
5.times {@secure.add(@amount_to_add)}
|
|
27
|
+
|
|
28
|
+
expect(@secure.amount).to eq(@amount + (4 * 100) + 500)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fund_list
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Victor Alexandre Franco Silva
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: |-
|
|
28
|
+
This RubyGem contains a nice-n-easy funding projects simulation, called FundList.
|
|
29
|
+
|
|
30
|
+
The sim runs in command-line, calling just the command crowd_fund (easy as that :0 )
|
|
31
|
+
|
|
32
|
+
You can choose the number of funding rounds and it will display the current stats of the projects.
|
|
33
|
+
|
|
34
|
+
You can also create a '.csv' file to hold projects, with a current amount and a target.
|
|
35
|
+
This file should be put next to the command when calling the sim.
|
|
36
|
+
|
|
37
|
+
File structure:
|
|
38
|
+
|
|
39
|
+
--NAME--|--TARGET--|--AMOUNT-- (This is just for explanatory purpose)
|
|
40
|
+
Project,1000,100
|
|
41
|
+
(The commas must be put into each string of projects, without blankspace.)
|
|
42
|
+
|
|
43
|
+
Have fun on this simulation. If you have any ideas, you can use the code,
|
|
44
|
+
which already is tested, to create a new, different, sim!
|
|
45
|
+
|
|
46
|
+
Good-bye !! =)
|
|
47
|
+
email: victor.alexandrefs@gmail.com
|
|
48
|
+
executables:
|
|
49
|
+
- crowd_fund
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- LICENSE
|
|
54
|
+
- README
|
|
55
|
+
- bin/crowd_fund
|
|
56
|
+
- bin/projects.csv
|
|
57
|
+
- lib/crowd_fund/die.rb
|
|
58
|
+
- lib/crowd_fund/fund_request.rb
|
|
59
|
+
- lib/crowd_fund/fundable.rb
|
|
60
|
+
- lib/crowd_fund/funding_round.rb
|
|
61
|
+
- lib/crowd_fund/grand_project.rb
|
|
62
|
+
- lib/crowd_fund/pledge_pool.rb
|
|
63
|
+
- lib/crowd_fund/printable.rb
|
|
64
|
+
- lib/crowd_fund/project.rb
|
|
65
|
+
- lib/crowd_fund/secure_project.rb
|
|
66
|
+
- spec/crowd_fund/fund_request_spec.rb
|
|
67
|
+
- spec/crowd_fund/grand_project_spec.rb
|
|
68
|
+
- spec/crowd_fund/pledge_pool_spec.rb
|
|
69
|
+
- spec/crowd_fund/project_spec.rb
|
|
70
|
+
- spec/crowd_fund/secure_project_spec.rb
|
|
71
|
+
homepage: http://github.com/victorfranco
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata: {}
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '1.9'
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubyforge_project:
|
|
91
|
+
rubygems_version: 2.4.8
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: A simple, fun, project funding simulation.
|
|
95
|
+
test_files:
|
|
96
|
+
- spec/crowd_fund/project_spec.rb
|
|
97
|
+
- spec/crowd_fund/secure_project_spec.rb
|
|
98
|
+
- spec/crowd_fund/fund_request_spec.rb
|
|
99
|
+
- spec/crowd_fund/pledge_pool_spec.rb
|
|
100
|
+
- spec/crowd_fund/grand_project_spec.rb
|