crowdfund_tblessing 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 +19 -0
- data/README +1 -0
- data/bin/crowdfund +31 -0
- data/bin/funding_needed.txt +4 -0
- data/bin/projects.csv +3 -0
- data/lib/crowdfund/die.rb +13 -0
- data/lib/crowdfund/fundable.rb +16 -0
- data/lib/crowdfund/funding_round.rb +19 -0
- data/lib/crowdfund/fundrequest.rb +98 -0
- data/lib/crowdfund/grant_project.rb +17 -0
- data/lib/crowdfund/matching_project.rb +30 -0
- data/lib/crowdfund/pledge.rb +15 -0
- data/lib/crowdfund/project.rb +50 -0
- data/spec/crowdfund/fundrequest_spec.rb +26 -0
- data/spec/crowdfund/project_spec.rb +58 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9272f00c19afd4b42faccba14ae53c27c40d327
|
4
|
+
data.tar.gz: 7a82874ae6cea7e71c6c687eab122572e7361653
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e7c7088108a85c0d371a5203109e9c1823ff68aba1cb9785f48a6dd3417dde3e99203ff482f69a81b7dc73056f32a7dc8a1b2fd85ffa9a66b690d2be647e8a8
|
7
|
+
data.tar.gz: e5aa05eb8cfd3394c724092cc63a453051feb4e9f64fe9a61ee38d074078246f9a4b43c00ef2d5e4e02ee9911e2e87267fff55cbee34241c311f48414a43e1c9
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2017 Travis Blessing
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is my second program, this is a program from pragmatic_studio to learn the Ruby language.
|
data/bin/crowdfund
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/crowdfund/fundrequest'
|
4
|
+
require_relative '../lib/crowdfund/project'
|
5
|
+
#require_relative '../lib/crowdfund/grant_project'
|
6
|
+
#require_relative '../lib/crowdfund/matching_project'
|
7
|
+
|
8
|
+
module CrowdFund
|
9
|
+
|
10
|
+
startups= FundRequest.new("VC-Friendly Start-up Projects")
|
11
|
+
default_project_file = File.join(File.dirname(__FILE__), 'projects.csv')
|
12
|
+
startups.load_project(ARGV.shift || default_project_file)
|
13
|
+
startups.request_funding(3)
|
14
|
+
startups.print_stats
|
15
|
+
|
16
|
+
loop do
|
17
|
+
puts "How many funding rounds? ('quit' or exit)"
|
18
|
+
answer = gets.chomp.downcase
|
19
|
+
case answer
|
20
|
+
when /\d+$/
|
21
|
+
startups.request_funding(answer.to_i)
|
22
|
+
when 'quit', 'exit'
|
23
|
+
startups.print_stats
|
24
|
+
break
|
25
|
+
else
|
26
|
+
puts "Please enter a number or ('quit' or exit)!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
startups.save_pledge_contributions
|
30
|
+
end
|
31
|
+
fundrequest = CrowdFund::FundRequest.new("VC-Friendly Start-up Projects")
|
data/bin/projects.csv
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
module CrowdFund
|
3
|
+
module Fundable
|
4
|
+
|
5
|
+
def add_funds
|
6
|
+
@funding += 25
|
7
|
+
puts "Project #{@name} received funds!"
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove_funds
|
11
|
+
@funding -= 15
|
12
|
+
puts "Project #{@name} lost funds!"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'pledge'
|
4
|
+
module CrowdFund
|
5
|
+
module FundingRound
|
6
|
+
def self.donations_made(project)
|
7
|
+
die = Die.new
|
8
|
+
number_roll = die.roll
|
9
|
+
if number_roll % 2 == 0
|
10
|
+
project.add_funds
|
11
|
+
else
|
12
|
+
project.remove_funds
|
13
|
+
end
|
14
|
+
|
15
|
+
pledges = Pledge.random
|
16
|
+
project.pledges_made(pledges)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'funding_round'
|
4
|
+
require_relative 'pledge'
|
5
|
+
require 'csv'
|
6
|
+
module CrowdFund
|
7
|
+
class FundRequest
|
8
|
+
|
9
|
+
def initialize(title)
|
10
|
+
@title= title
|
11
|
+
@projects= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_project(name)
|
15
|
+
@projects << name
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_project(from_file='projects.csv')
|
19
|
+
CSV.foreach(from_file).each do |row|
|
20
|
+
project = Project.new(row[0], row[1].to_i, row[2].to_i)
|
21
|
+
add_project(project)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def pledge_contributions(project)
|
26
|
+
formatted_name= project.name.ljust(20, '.')
|
27
|
+
puts "#{formatted_name} #{project.funding_needed}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def save_pledge_contributions(to_file= 'funding_needed.txt')
|
31
|
+
File.open(to_file, "w") do |file|
|
32
|
+
file.puts "#{@title} still needing funding:"
|
33
|
+
@projects.sort.each do |project|
|
34
|
+
file.puts pledge_contributions(project)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def total_funds
|
40
|
+
@projects.reduce(0) {|sum, p| sum + p.funds}
|
41
|
+
end
|
42
|
+
|
43
|
+
def print_stats
|
44
|
+
fully_funded, under_funded= @projects.partition { |project| project.funded?}
|
45
|
+
puts "\n#{@title} Statistics:\n"
|
46
|
+
|
47
|
+
puts "\n#{fully_funded.size} has been fully_funded:\n"
|
48
|
+
fully_funded.each do |project|
|
49
|
+
puts "#{project.name} (#{project.funding})\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "\n#{under_funded.size} has been under_funded:\n"
|
53
|
+
under_funded.each do |project|
|
54
|
+
puts "#{project.name} (#{project.funding})"
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "\n#{under_funded.size} projects needing contributions:"
|
58
|
+
@projects.sort.each do |project|
|
59
|
+
pledge_contributions(project)
|
60
|
+
end
|
61
|
+
|
62
|
+
@projects.each do |project|
|
63
|
+
puts "#{project.name}'s total funds:\n"
|
64
|
+
puts "\n$#{project.funds} total funds."
|
65
|
+
end
|
66
|
+
puts "\n$#{total_funds} total funds from pledges."
|
67
|
+
|
68
|
+
@projects.each do |project|
|
69
|
+
puts "\nProject #{project.name} pledges:\n"
|
70
|
+
project.each_pledge_donated do |pledge|
|
71
|
+
puts "$#{pledge.amount} in #{pledge.level} pledges"
|
72
|
+
end
|
73
|
+
puts "$#{project.funds} in total pledges\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def request_funding(rounds)
|
78
|
+
puts "There are #{@projects.size} projects:"
|
79
|
+
@projects.each do |project|
|
80
|
+
puts project
|
81
|
+
end
|
82
|
+
pledges= Pledge::PLEDGES
|
83
|
+
puts "There are #{pledges.size} possible pledge amounts:\n"
|
84
|
+
pledges.each do |pledge|
|
85
|
+
puts "A #{pledge.level} pledge is worth $#{pledge.amount}."
|
86
|
+
end
|
87
|
+
1.upto(rounds).each do |round|
|
88
|
+
puts "\n Round #{round}:"
|
89
|
+
@projects.each do |project|
|
90
|
+
FundingRound.donations_made(project)
|
91
|
+
puts project
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
module CrowdFund
|
3
|
+
class GrantProject < Project
|
4
|
+
def remove_funds
|
5
|
+
@funding -= 0
|
6
|
+
puts "#{@name} has not lost or gained any funds."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if __FILE__ == $0
|
11
|
+
grant = GrantProject.new("Project 123", 500, 100)
|
12
|
+
|
13
|
+
puts "#{grant.name} has $#{grant.total_funds} in funding towards a goal of $#{project.target}."
|
14
|
+
grant.remove_funds
|
15
|
+
puts "#{grant.name} has $#{grant.total_funds} in funding towards a goal of $#{project.target}."
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
module CrowdFund
|
3
|
+
class MatchingProject < Project
|
4
|
+
|
5
|
+
def initialize(name, target, funding=0)
|
6
|
+
super(name, target, funding)
|
7
|
+
@halfway_funded = target / 2
|
8
|
+
end
|
9
|
+
|
10
|
+
def halfway_funded?
|
11
|
+
@halfway_funded <= funding
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_funds
|
15
|
+
if halfway_funded?
|
16
|
+
@funding += (25*2)
|
17
|
+
puts "#{@name} has received at least half its funding!" if halfway_funded?
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
matchingproject = MatchingProject.new("Matching 123", 100, 0)
|
27
|
+
3.times { matchingproject.add_funds }
|
28
|
+
puts matchingproject.funding
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'pledge'
|
2
|
+
require_relative 'fundable'
|
3
|
+
module CrowdFund
|
4
|
+
class Project
|
5
|
+
include Fundable
|
6
|
+
attr_accessor :name
|
7
|
+
attr_reader :funding, :target
|
8
|
+
|
9
|
+
def initialize(name, funding=0, target)
|
10
|
+
@name= name
|
11
|
+
@funding= funding
|
12
|
+
@target= target
|
13
|
+
@pledges_made= Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"Project #{@name} has $#{@funding} in funding towards a goal of $#{@target}, we still need $#{funding_needed} to hit our goal."
|
18
|
+
end
|
19
|
+
|
20
|
+
def funded?
|
21
|
+
@funding >= @target
|
22
|
+
end
|
23
|
+
|
24
|
+
def <=>(other)
|
25
|
+
other.funding_needed <=> funding_needed
|
26
|
+
end
|
27
|
+
|
28
|
+
def pledges_made(pledge)
|
29
|
+
@pledges_made[pledge.level] += pledge.amount
|
30
|
+
puts "Project #{@name} received a #{pledge.level} pledge worth $#{pledge.amount}."
|
31
|
+
puts "Project #{@name}'s pledges: #{@pledges_made}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def each_pledge_donated
|
35
|
+
@pledges_made.each do |level, amount|
|
36
|
+
yield Pledges.new(level, amount)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def funds
|
41
|
+
@pledges_made.values.reduce(0, :+)
|
42
|
+
end
|
43
|
+
|
44
|
+
def funding_needed
|
45
|
+
@target - @funding
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'fundrequest'
|
2
|
+
|
3
|
+
describe FundRequest do
|
4
|
+
before do
|
5
|
+
@fundrequest= FundRequest.new("VC-Friendly Start-up Projects")
|
6
|
+
|
7
|
+
@initial_fund= 0
|
8
|
+
@project= Project.new('LMN', @initial_fund, 3000)
|
9
|
+
|
10
|
+
@fundrequest.add_project(@project)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "die is rolled even, add funds to project" do
|
14
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(2, 4, 6)
|
15
|
+
|
16
|
+
@fundrequest.request_funding
|
17
|
+
expect(@project.funding).to eq(@initial_fund + 25)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "die is rolled odd, remove funds from project" do
|
21
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(1, 3, 5)
|
22
|
+
|
23
|
+
@fundrequest.request_funding
|
24
|
+
expect(@project.funding).to eq(@initial_fund - 15)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
|
3
|
+
describe Project do
|
4
|
+
|
5
|
+
before do
|
6
|
+
$stdout= StringIO.new
|
7
|
+
@project= Project.new('LMN', 3000)
|
8
|
+
@initial_funds= 0
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has an initial target funding amount" do
|
12
|
+
|
13
|
+
expect(@project.target).to eq(3000)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "computes the total funding outstanding as the target funding amount minus the funding amount" do
|
17
|
+
|
18
|
+
expect(@project.funding_needed).to eq(3000 - @initial_funds)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "increases funds by 25 when funds are added" do
|
22
|
+
|
23
|
+
@project.add_funds
|
24
|
+
|
25
|
+
expect(@project.funding).to eq(@initial_funds + 25)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "decreases funds by 15 when funds are removed" do
|
29
|
+
|
30
|
+
@project.remove_funds
|
31
|
+
|
32
|
+
expect(@project.funding).to eq(@initial_funds - 15)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a default value of 0 for funding amount" do
|
36
|
+
|
37
|
+
expect(@project.funding).to eq(0)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "funding equals or exceeds the target funding amount" do
|
41
|
+
before do
|
42
|
+
@project= Project.new('LMN', 3500, 3000)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "project is being funded" do
|
46
|
+
expect(@project).to be_funded
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context "funding is less than the target funding amount " do
|
50
|
+
before do
|
51
|
+
@project= Project.new('LMN', 2500, 3000)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "project is not being funded" do
|
55
|
+
expect(@project).not_to be_funded
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crowdfund_tblessing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Blessing
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-05 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: This is my second program, this is a program from pragmatic_studio to
|
28
|
+
learn the Ruby language.
|
29
|
+
email: travis@tnthealthandfitness.com
|
30
|
+
executables:
|
31
|
+
- crowdfund
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- bin/crowdfund
|
38
|
+
- bin/funding_needed.txt
|
39
|
+
- bin/projects.csv
|
40
|
+
- lib/crowdfund/die.rb
|
41
|
+
- lib/crowdfund/fundable.rb
|
42
|
+
- lib/crowdfund/funding_round.rb
|
43
|
+
- lib/crowdfund/fundrequest.rb
|
44
|
+
- lib/crowdfund/grant_project.rb
|
45
|
+
- lib/crowdfund/matching_project.rb
|
46
|
+
- lib/crowdfund/pledge.rb
|
47
|
+
- lib/crowdfund/project.rb
|
48
|
+
- spec/crowdfund/fundrequest_spec.rb
|
49
|
+
- spec/crowdfund/project_spec.rb
|
50
|
+
homepage: http://tnthealthandfitness.com
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.9'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.6.14
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Projects crowdfund
|
74
|
+
test_files:
|
75
|
+
- spec/crowdfund/project_spec.rb
|
76
|
+
- spec/crowdfund/fundrequest_spec.rb
|