dstfvrts_fundraiser 1.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.md +1 -0
- data/bin/crowdfund +40 -0
- data/bin/fundingresults.txt +4 -0
- data/bin/projects.csv +3 -0
- data/lib/fundraising/die.rb +14 -0
- data/lib/fundraising/fund_manager.rb +85 -0
- data/lib/fundraising/fundable.rb +17 -0
- data/lib/fundraising/funding_round.rb +23 -0
- data/lib/fundraising/grant_project.rb +10 -0
- data/lib/fundraising/pledge.rb +18 -0
- data/lib/fundraising/project.rb +43 -0
- data/spec/fund_manager_spec.rb +28 -0
- data/spec/project_spec.rb +34 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 71f687d74e909fbf57517d38ed59a39e1bc4a38203a76486178c8e0c8dad0305
|
|
4
|
+
data.tar.gz: 546c7b305c877f936e7f15c1a6b94e43eee5a5637998c338f91a8af00c819cb3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 581cf80573afd6281802868caa8dfd3295edb51ba470877aaa8f82160c2a94e3aed558723bb44138ae20c3608d424c59c79469cfa1245783e97aa7fc236cf448
|
|
7
|
+
data.tar.gz: 1b1b1d5ac9c3ad22da0bff041c5c27637fac6af49ed364d4d21baee9f76cedf5c483ced3f340ec87baebe68c158bc2d7949ee7b7bd3cedce8b185acfbdea5ca7
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2019 Dustin Favorite
|
|
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.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# pragmatic-studio-fundraising
|
data/bin/crowdfund
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require './lib/fundraising/project'
|
|
4
|
+
require './lib/fundraising/fund_manager'
|
|
5
|
+
require './lib/fundraising/grant_project'
|
|
6
|
+
|
|
7
|
+
alpha = Fundraising::Project.new("alpha", 10000, 100000)
|
|
8
|
+
beta = Fundraising::Project.new("beta")
|
|
9
|
+
gamma = Fundraising::Project.new("gamma", 400, 1200)
|
|
10
|
+
|
|
11
|
+
favorite_funding = Fundraising::Hedgefund.new("Favorite LLC")
|
|
12
|
+
=begin
|
|
13
|
+
favorite_funding.add_project(alpha)
|
|
14
|
+
favorite_funding.add_project(beta)
|
|
15
|
+
favorite_funding.add_project(gamma)
|
|
16
|
+
=end
|
|
17
|
+
favorite_funding.load_projects("projects.csv")
|
|
18
|
+
favorite_funding.add_project(Fundraising::GrantProject.new("Grant Proj"))
|
|
19
|
+
loop do
|
|
20
|
+
puts "Please enter days of funding: ('e' to exit)"
|
|
21
|
+
answer = gets.chomp
|
|
22
|
+
|
|
23
|
+
case answer
|
|
24
|
+
when /^\d+$/
|
|
25
|
+
favorite_funding.update(answer.to_i)
|
|
26
|
+
when /[e]/
|
|
27
|
+
break
|
|
28
|
+
else
|
|
29
|
+
puts "Please enter a number or 'e' to exit."
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
favorite_funding.projects.each_with_index do |project, index|
|
|
34
|
+
if project.funds_needed > 0
|
|
35
|
+
favorite_funding.projects.delete(project)
|
|
36
|
+
favorite_funding.add_project(Fundraising::Project.new("Project #{index}"))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
favorite_funding.save_stats
|
data/bin/projects.csv
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
require_relative 'project'
|
|
3
|
+
require_relative 'funding_round'
|
|
4
|
+
|
|
5
|
+
module Fundraising
|
|
6
|
+
class Hedgefund
|
|
7
|
+
attr_reader :co_name, :projects
|
|
8
|
+
|
|
9
|
+
def initialize(name)
|
|
10
|
+
@co_name = name
|
|
11
|
+
@projects = []
|
|
12
|
+
@die = Die.new()
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_project(project)
|
|
16
|
+
projects.push(project)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def load_projects(filename='projects.csv')
|
|
20
|
+
projects = CSV.open "./bin/#{filename}", headers: false
|
|
21
|
+
projects.each do |row|
|
|
22
|
+
name = row[0]
|
|
23
|
+
funding = row[1].to_i
|
|
24
|
+
target = row[2].to_i
|
|
25
|
+
add_project(Project.new(name, funding, target))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def status
|
|
30
|
+
puts "There are #{projects.length} active projects."
|
|
31
|
+
projects
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def save_stats(filename="fundingresults.txt")
|
|
35
|
+
File.open("./bin/#{filename}", "w") do |file|
|
|
36
|
+
@projects.each do |project|
|
|
37
|
+
file.puts "#{project.name}...#{project.funding}...#{project.funding_target}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def update(days)
|
|
43
|
+
|
|
44
|
+
1.upto(days) do |d|
|
|
45
|
+
puts "Day #{d}:"
|
|
46
|
+
@projects.each do |project|
|
|
47
|
+
FundingRound.update(project)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
under_funded, fully_funded = projects.partition { |p| p.funds_needed >= 0}
|
|
52
|
+
|
|
53
|
+
if fully_funded.size == 0
|
|
54
|
+
puts "No projects are fully funded."
|
|
55
|
+
else
|
|
56
|
+
puts "Fundraising completed.\nFully funded projects:"
|
|
57
|
+
fully_funded.each do |p|
|
|
58
|
+
puts "#{p.name}, #{p.funding} out of #{p.funding_target}"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if under_funded.size == 0
|
|
63
|
+
puts "No projects are in need of further contributions."
|
|
64
|
+
else
|
|
65
|
+
under_funded.sort_by do |first, second|
|
|
66
|
+
return first unless second
|
|
67
|
+
first <=> second
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
puts "Projects in need of contributions:"
|
|
71
|
+
under_funded.each do |p|
|
|
72
|
+
puts "#{p.name}, #{p.funding} out of #{p.funding_target}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
puts "All pledges:"
|
|
77
|
+
projects.each do |p|
|
|
78
|
+
puts "#{p.name} pledges:"
|
|
79
|
+
p.each_pledge do |pledge|
|
|
80
|
+
puts "$#{pledge.amount} in #{pledge.name} pledges"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Fundraising
|
|
2
|
+
module Fundable
|
|
3
|
+
def add_funds(amount)
|
|
4
|
+
self.funding += amount
|
|
5
|
+
puts "Project #{name} added funds!"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def remove_funds(amount)
|
|
9
|
+
self.funding -= amount
|
|
10
|
+
puts "Project #{name} lost funds!"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def funds_needed
|
|
14
|
+
funding_target - funding
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'pledge'
|
|
3
|
+
|
|
4
|
+
module Fundraising
|
|
5
|
+
module FundingRound
|
|
6
|
+
def self.update(project)
|
|
7
|
+
@die = Die.new
|
|
8
|
+
@die.roll
|
|
9
|
+
if @die.number % 2 == 0
|
|
10
|
+
project.add_funds(100)
|
|
11
|
+
else
|
|
12
|
+
project.remove_funds(100)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
if project.funds_needed <= 0
|
|
16
|
+
puts "#{project.name} is fully funded!"
|
|
17
|
+
else
|
|
18
|
+
pledge = Donations.random
|
|
19
|
+
project.pledges(pledge)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Fundraising
|
|
2
|
+
Pledge = Struct.new(:name, :amount)
|
|
3
|
+
|
|
4
|
+
module Donations
|
|
5
|
+
extend self
|
|
6
|
+
|
|
7
|
+
PLEDGES = [
|
|
8
|
+
Pledge.new(:bronze, 50),
|
|
9
|
+
Pledge.new(:silver, 75),
|
|
10
|
+
Pledge.new(:gold, 100),
|
|
11
|
+
Pledge.new(:platinum, 150)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def random
|
|
15
|
+
PLEDGES[rand(4)]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative "pledge"
|
|
2
|
+
require_relative "fundable"
|
|
3
|
+
|
|
4
|
+
module Fundraising
|
|
5
|
+
class Project
|
|
6
|
+
include Fundable
|
|
7
|
+
|
|
8
|
+
attr_accessor :name, :funding, :funding_target
|
|
9
|
+
|
|
10
|
+
def initialize(name, funding=1000, funding_target=10000)
|
|
11
|
+
@name = name.capitalize
|
|
12
|
+
@funding = funding
|
|
13
|
+
@funding_target = funding_target
|
|
14
|
+
@pledges = Hash.new(0)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def pledges(pledge)
|
|
18
|
+
@pledges[pledge.name] += pledge.amount
|
|
19
|
+
@funding += pledge.amount
|
|
20
|
+
puts "#{name} received a #{pledge.name} pledge worth #{pledge.amount}!"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def each_pledge
|
|
24
|
+
@pledges.each do |name, amount|
|
|
25
|
+
yield Pledge.new(name, amount)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_s
|
|
30
|
+
"Project: #{name}\tFunds needed: #{funds_needed}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def <=> (other)
|
|
34
|
+
funds_needed <=> other.funds_needed
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if __FILE__ == $0
|
|
39
|
+
alpha = Project.new("Alpha", 1200, 1800)
|
|
40
|
+
alpha.add_funds(400)
|
|
41
|
+
puts Alpha
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require './lib/fundraising/fund_manager'
|
|
2
|
+
|
|
3
|
+
module Fundraising
|
|
4
|
+
describe Hedgefund do
|
|
5
|
+
before do
|
|
6
|
+
@favoriteLLC = Hedgefund.new('Favorite LLC');
|
|
7
|
+
@project = Project.new('Alpha', 100, 1000);
|
|
8
|
+
@favoriteLLC.add_project(@project)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'adds funds if a even number is rolled' do
|
|
12
|
+
allow_any_instance_of(Die).to receive(:number).and_return(2)
|
|
13
|
+
|
|
14
|
+
@favoriteLLC.update(4)
|
|
15
|
+
|
|
16
|
+
expect(@project.funding).to be > 100
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'deducts funds if an odd number is rolled' do
|
|
20
|
+
allow_any_instance_of(Die).to receive(:number).and_return(3)
|
|
21
|
+
@project2 = Project.new('Beta', 60, 100)
|
|
22
|
+
@favoriteLLC.add_project(@project2)
|
|
23
|
+
@favoriteLLC.update(4)
|
|
24
|
+
|
|
25
|
+
expect(@project2.funding). to be < 60
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require './lib/fundraising/project'
|
|
2
|
+
require './lib/fundraising/pledge'
|
|
3
|
+
require 'pry'
|
|
4
|
+
|
|
5
|
+
module Fundraising
|
|
6
|
+
describe Project do
|
|
7
|
+
before do
|
|
8
|
+
@project = Project.new("ABC", 100, 1000)
|
|
9
|
+
@amount = 50
|
|
10
|
+
@bronzePledge = Pledge.new(:bronze, 50)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'adds a specified amount to total funding' do
|
|
14
|
+
@project.add_funds(@amount)
|
|
15
|
+
|
|
16
|
+
expect(@project.funding).to eq(150)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'subtracts a specified amount to total funding' do
|
|
20
|
+
@project.remove_funds(@amount)
|
|
21
|
+
|
|
22
|
+
expect(@project.funding).to eq(50)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'adds pledges and associated amount to total funding' do
|
|
26
|
+
@project.pledges(@bronzePledge)
|
|
27
|
+
|
|
28
|
+
expect(@project.funding).to eq(150)
|
|
29
|
+
@project.each_pledge do |pledge|
|
|
30
|
+
expect(pledge).to eq(@bronzePledge)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dstfvrts_fundraiser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- dstfvrt
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-05-08 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: "# pragmatic-studio-fundraising\n"
|
|
34
|
+
email: dstfvrt@gmail.com
|
|
35
|
+
executables:
|
|
36
|
+
- crowdfund
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- LICENSE
|
|
41
|
+
- README.md
|
|
42
|
+
- bin/crowdfund
|
|
43
|
+
- bin/fundingresults.txt
|
|
44
|
+
- bin/projects.csv
|
|
45
|
+
- lib/fundraising/die.rb
|
|
46
|
+
- lib/fundraising/fund_manager.rb
|
|
47
|
+
- lib/fundraising/fundable.rb
|
|
48
|
+
- lib/fundraising/funding_round.rb
|
|
49
|
+
- lib/fundraising/grant_project.rb
|
|
50
|
+
- lib/fundraising/pledge.rb
|
|
51
|
+
- lib/fundraising/project.rb
|
|
52
|
+
- spec/fund_manager_spec.rb
|
|
53
|
+
- spec/project_spec.rb
|
|
54
|
+
homepage: https://github.com/dstfvrt/pragmatic-studio-fundraising
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata: {}
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '1.9'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubygems_version: 3.0.3
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: CLI text fundraiser
|
|
77
|
+
test_files:
|
|
78
|
+
- spec/project_spec.rb
|
|
79
|
+
- spec/fund_manager_spec.rb
|