crowd_fund 1.1.1
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/bin/crowd_fund +32 -0
- data/bin/user_input.csv +3 -0
- data/lib/crowd_fund/Die.rb +18 -0
- data/lib/crowd_fund/fundable.rb +32 -0
- data/lib/crowd_fund/funding_round.rb +17 -0
- data/lib/crowd_fund/fundrequest.rb +88 -0
- data/lib/crowd_fund/pledge_pool.rb +21 -0
- data/lib/crowd_fund/project.rb +57 -0
- data/lib/crowd_fund/specialized_behavior.rb +10 -0
- data/spec/crowd_fund/fundrequest_spec.rb +33 -0
- data/spec/crowd_fund/project_spec.rb +87 -0
- data/spec/crowd_fund/specialized_behavior_spec.rb +9 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c8c67cf13d9148d676349643685c46c230c70b0c86d8208ddbf81428ddb1161
|
4
|
+
data.tar.gz: a74393eabd4c71fdd52e8d6a45a3b9f4743995e67acd00dcfffbf87ad9e4149b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 787ffa34653a733ce6cb31ebed314c9266bf0f8115be98d81999ccbee37f7314eaca1e8f49ffb374eee412432b5869596e7ee8325fe6c693c3769d4ffaf29485
|
7
|
+
data.tar.gz: dc96e097c984106a44691dd24c86a48296425b414c6d51061791220c608e1e4896e22a152f21aef36be2d8614a49a1531a8312afe6c894296bc0da129541f042
|
data/bin/crowd_fund
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative 'project'
|
4
|
+
require_relative 'pledge_pool'
|
5
|
+
require_relative 'specialized_behavior'
|
6
|
+
|
7
|
+
|
8
|
+
project1 = Project.new("Project ABC", 5000, 1000)
|
9
|
+
project2 = Project.new("Project LMN", 3000, 500)
|
10
|
+
project3 = Project.new("Project XYZ", 75, 25)
|
11
|
+
|
12
|
+
projects = FundRequest.new("VC-Friendly Start-up Projects")
|
13
|
+
projects.load_funding(ARGV.shift || "user_input.csv")
|
14
|
+
|
15
|
+
specializedbehavior = SpecializedBehavior.new("green", 1000)
|
16
|
+
projects.add_funds
|
17
|
+
|
18
|
+
loop do
|
19
|
+
puts "\nHow many project rounds? ('quit' to exit)"
|
20
|
+
answer = gets.chomp.downcase
|
21
|
+
case answer
|
22
|
+
when /^\d+$/
|
23
|
+
projects.request_funding(answer.to_i)
|
24
|
+
when 'quit', 'exit'
|
25
|
+
projects.print_stats
|
26
|
+
break
|
27
|
+
else
|
28
|
+
puts "Please enter a number or quit"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
projects.save_fund_amount
|
data/bin/user_input.csv
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fundable
|
2
|
+
|
3
|
+
def total_funds
|
4
|
+
self.funding + pledges
|
5
|
+
end
|
6
|
+
|
7
|
+
def remove_funds
|
8
|
+
self.funding -= 15
|
9
|
+
puts "#{name} lost some funds!"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_funds
|
13
|
+
self.funding += 25
|
14
|
+
puts "#{name} got more funds!"
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_funding_outstanding
|
18
|
+
self.target - self.funding
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=> (other_funding)
|
22
|
+
other_funding.name <=> name
|
23
|
+
end
|
24
|
+
|
25
|
+
def fully_funded?
|
26
|
+
total_funding_outstanding <= 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def status
|
30
|
+
fully_funded? ? "Fully_funded" : "Under_funded"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CrowdFund
|
2
|
+
module FundingRound
|
3
|
+
def self.round_funds(project)
|
4
|
+
die = Die.new
|
5
|
+
number_rolled = die.roll
|
6
|
+
|
7
|
+
if number_rolled.odd?
|
8
|
+
project.remove_funds
|
9
|
+
else
|
10
|
+
project.add_funds
|
11
|
+
end
|
12
|
+
|
13
|
+
pledge = PledgePool.random
|
14
|
+
project.found_pledge(pledge)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'funding_round'
|
4
|
+
require_relative 'pledge_pool'
|
5
|
+
require 'CSV'
|
6
|
+
|
7
|
+
module CrowdFund
|
8
|
+
class FundRequest
|
9
|
+
|
10
|
+
attr_reader :title
|
11
|
+
|
12
|
+
def initialize (title)
|
13
|
+
@title = title
|
14
|
+
@projects = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_fund_amount(to_file="fund_amount.txt")
|
18
|
+
File.open(to_file, 'w') do |file|
|
19
|
+
file.puts "#{title} total funds:"
|
20
|
+
@projects.sort.each do |project|
|
21
|
+
puts high_funding_amount(project)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def high_funding_amount(project)
|
27
|
+
formatted_name = project.name.ljust(20, '.')
|
28
|
+
puts "#{formatted_name} $#{project.total_funding_outstanding}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_funding(from_file)
|
32
|
+
CSV.foreach(from_file) do |row|
|
33
|
+
project = Project.new(row[0], row[1].to_i)
|
34
|
+
add_project(project)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def add_project(new_project)
|
40
|
+
@projects.push(new_project)
|
41
|
+
end
|
42
|
+
|
43
|
+
def request_funding(rounds)
|
44
|
+
puts "There are #{@projects.size} projects that you could fund."
|
45
|
+
puts @projects
|
46
|
+
|
47
|
+
pledge = PledgePool::PLEDGES
|
48
|
+
puts "There are #{pledge.size} possible pledge amounts:"
|
49
|
+
|
50
|
+
pledge.each do |pledge|
|
51
|
+
puts "A #{pledge.name} pledge is worth $#{pledge.amount}."
|
52
|
+
end
|
53
|
+
|
54
|
+
1.upto(rounds) do |round|
|
55
|
+
puts "\n Funding Round #{round}:"
|
56
|
+
|
57
|
+
@projects.each do |project|
|
58
|
+
FundingRound.round_funds(project)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def print_stats
|
63
|
+
puts "\n#{@title}'s' status:"
|
64
|
+
|
65
|
+
fully_funded, under_funded = @projects.partition { |project| project.fully_funded? }
|
66
|
+
|
67
|
+
puts "\nFully_funded:"
|
68
|
+
puts fully_funded.sort
|
69
|
+
|
70
|
+
puts "\nUnder_funded:"
|
71
|
+
puts under_funded.sort
|
72
|
+
|
73
|
+
puts "\n#{@title} fund:"
|
74
|
+
@projects.sort.each do |project|
|
75
|
+
puts high_funding_amount(project)
|
76
|
+
|
77
|
+
@projects.sort.each do |project|
|
78
|
+
puts "\n#{project.name}'s pledges:"
|
79
|
+
project.each_pledge do |pledge|
|
80
|
+
puts "$#{pledge.amount} in #{pledge.name} pledges"
|
81
|
+
end
|
82
|
+
puts "$#{project.pledges} grand total pledge"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CrowdFund
|
2
|
+
Pledge = Struct.new(:name, :amount)
|
3
|
+
|
4
|
+
module PledgePool
|
5
|
+
PLEDGES = [
|
6
|
+
Pledge.new(:silver, 75),
|
7
|
+
Pledge.new(:gold, 100),
|
8
|
+
Pledge.new(:bronze, 50),
|
9
|
+
]
|
10
|
+
|
11
|
+
def self.random
|
12
|
+
PLEDGES.sample
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if __FILE__ == $0
|
17
|
+
puts Pledge::PLEDGES
|
18
|
+
pledge = Pledge.random
|
19
|
+
puts "A #{pledge.name} pledge is worth ($#{pledge.amount})."
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative 'fundrequest'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'pledge_pool'
|
4
|
+
require_relative 'fundable'
|
5
|
+
|
6
|
+
module CrowdFund
|
7
|
+
class Project
|
8
|
+
include Fundable
|
9
|
+
|
10
|
+
attr_accessor :name, :funding
|
11
|
+
attr_reader :funding, :target
|
12
|
+
|
13
|
+
def initialize(name, target_amount, funding=0)
|
14
|
+
@name = name
|
15
|
+
@target = target_amount
|
16
|
+
@funding = funding
|
17
|
+
@found_pledge = Hash.new(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_csv(string)
|
21
|
+
name, funding, target = string.split(',')
|
22
|
+
Project.new(name, Integer(funding), Integer(target))
|
23
|
+
end
|
24
|
+
|
25
|
+
def pledges
|
26
|
+
@found_pledge.values.reduce(0, :+)
|
27
|
+
end
|
28
|
+
|
29
|
+
def each_pledge
|
30
|
+
@found_pledge.each do |name, amount|
|
31
|
+
pledge = Pledge.new(name, amount)
|
32
|
+
yield pledge
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def found_pledge(pledge)
|
37
|
+
@found_pledge[pledge.name] += pledge.amount
|
38
|
+
|
39
|
+
puts "#{@name} received a #{pledge.name} pledge worth #{pledge.amount}."
|
40
|
+
puts "#{@name}'s pledges: #{@found_pledge} "
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"I'm #{@name}'s with a pledge = #{@found_pledge}. "
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if __FILE__ == $0
|
50
|
+
project = Project.new("Project ABC", 5000, 1000)
|
51
|
+
puts project.name
|
52
|
+
puts project.funding
|
53
|
+
project.remove_funds
|
54
|
+
puts project.funding
|
55
|
+
project.add_funds
|
56
|
+
puts project.funding
|
57
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'crowd_fund/fundrequest'
|
2
|
+
require 'crowd_fund/funding_round'
|
3
|
+
|
4
|
+
module CrowdFund
|
5
|
+
describe FundRequest do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@fundrequest = FundRequest.new("VC-Friendly Start-up Projects")
|
9
|
+
|
10
|
+
@initial_funds = 1000
|
11
|
+
@project = Project.new("Project ABC", 5000, @initial_funds)
|
12
|
+
$stdout = StringIO.new
|
13
|
+
|
14
|
+
@fundrequest.add_project(@project)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "adds funds to a project if an even number is rolled" do
|
18
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(4)
|
19
|
+
|
20
|
+
@fundrequest.request_funding(1)
|
21
|
+
|
22
|
+
expect(@project.funding).to eq(@initial_funds + 25)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "removes funds to a project if an odd number is rolled" do
|
26
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
27
|
+
|
28
|
+
@fundrequest.request_funding(1)
|
29
|
+
|
30
|
+
expect(@project.funding).to eq(@initial_funds - 15)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'crowd_fund/project'
|
2
|
+
|
3
|
+
module CrowdFund
|
4
|
+
describe Project do
|
5
|
+
before do
|
6
|
+
@funding = 1000
|
7
|
+
@project = Project.new("Project ABC", 5000, @funding)
|
8
|
+
$stdout = StringIO.new
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
it "has an inital target funding amount" do
|
13
|
+
expect(@project.target).to eq(5000)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "computes the total funding outstanding as the target funding amount minus the funding amount" do
|
17
|
+
expect(@project.total_funding_outstanding).to eq(5000 - @funding)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "increases funds by 25 when funds are added" do
|
21
|
+
@project.add_funds
|
22
|
+
|
23
|
+
expect(@project.funding).to eq(@funding + 25)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "decreases funds by 15 when funds are removed" do
|
27
|
+
@project.remove_funds
|
28
|
+
|
29
|
+
expect(@project.funding).to eq(@funding - 15)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "created without a funding amount" do
|
33
|
+
before do
|
34
|
+
@project = Project.new("Project ABC", 5000)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a default funding amount of 0" do
|
38
|
+
@project.funding
|
39
|
+
|
40
|
+
expect(@project.funding).to eq(0)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when total funding outstanding is less than or equal to 0" do
|
45
|
+
before do
|
46
|
+
@project = Project.new("Project ABC", 5000 , 5000)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is fully funded" do
|
50
|
+
@project.should be_fully_funded
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when total funding outstanding is greater than 0" do
|
55
|
+
before do
|
56
|
+
@project = Project.new("Project ABC", 5000, 1000)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is under-funded" do
|
60
|
+
@project.should_not be_fully_funded
|
61
|
+
end
|
62
|
+
|
63
|
+
it "computes pledges as the sum of all pledges" do
|
64
|
+
expect(@project.pledges).to eq(0)
|
65
|
+
|
66
|
+
@project.found_pledge(Pledge.new(:silver, 75))
|
67
|
+
|
68
|
+
expect(@project.pledges).to eq(75)
|
69
|
+
|
70
|
+
@project.found_pledge(Pledge.new(:gold, 100))
|
71
|
+
|
72
|
+
expect(@project.pledges).to eq(175)
|
73
|
+
|
74
|
+
@project.found_pledge(Pledge.new(:gold, 100))
|
75
|
+
|
76
|
+
expect(@project.pledges).to eq(275)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "computes total funds as the sum of a projects funding and pledges" do
|
81
|
+
@project.found_pledge(Pledge.new(:gold, 100))
|
82
|
+
@project.found_pledge(Pledge.new(:gold, 100))
|
83
|
+
|
84
|
+
expect(@project.total_funds).to eq(1200)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crowd_fund
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Spradling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-31 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: 2.8.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.8'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.8'
|
33
|
+
description: "# crowd_fund\n"
|
34
|
+
email: dspradling@acsdetaso.com
|
35
|
+
executables:
|
36
|
+
- crowd_fund
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- bin/crowd_fund
|
41
|
+
- bin/user_input.csv
|
42
|
+
- lib/crowd_fund/Die.rb
|
43
|
+
- lib/crowd_fund/fundable.rb
|
44
|
+
- lib/crowd_fund/funding_round.rb
|
45
|
+
- lib/crowd_fund/fundrequest.rb
|
46
|
+
- lib/crowd_fund/pledge_pool.rb
|
47
|
+
- lib/crowd_fund/project.rb
|
48
|
+
- lib/crowd_fund/specialized_behavior.rb
|
49
|
+
- spec/crowd_fund/fundrequest_spec.rb
|
50
|
+
- spec/crowd_fund/project_spec.rb
|
51
|
+
- spec/crowd_fund/specialized_behavior_spec.rb
|
52
|
+
homepage: https://github.com/jspradling83/crowd_fund
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '1.9'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: game involving funds
|
75
|
+
test_files:
|
76
|
+
- spec/crowd_fund/project_spec.rb
|
77
|
+
- spec/crowd_fund/fundrequest_spec.rb
|
78
|
+
- spec/crowd_fund/specialized_behavior_spec.rb
|