crowdfund_mike_brooks 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 +1 -0
- data/README +1 -0
- data/bin/crowdfund +193 -0
- data/bin/save.txt +4 -0
- data/bin/users_projects_csv.csv +3 -0
- data/lib/top/dieroll.rb +19 -0
- data/lib/top/fundable.rb +21 -0
- data/lib/top/fundinground.rb +23 -0
- data/lib/top/fundrequest.rb +125 -0
- data/lib/top/grant_project.rb +25 -0
- data/lib/top/match_project.rb +43 -0
- data/lib/top/pledge.rb +37 -0
- data/lib/top/project.rb +83 -0
- data/spec/top/fundrequest_spec.rb +41 -0
- data/spec/top/pledge_spec.rb +45 -0
- data/spec/top/project_spec.rb +85 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd1a1386b906a2d43137bc4f08e45b0f24cbd019
|
4
|
+
data.tar.gz: a3f5afe19280f11c7aa94cc3d56cd91e3ccd2e10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a82e31c47d177a1fb3e483862d75d20c5c22b4cf531c6058da6196f3ef607851a3d62321b4df4e19f37e9c9e21bc97c19f1208c241bc705ae212d08aa276b491
|
7
|
+
data.tar.gz: 97edadf8010d67866aca6381ac3e9c36a894cc491c2237c50ef5cc6a9268302ee95dbffb783baa9002d3a30cb3067540ea862866d27d7aa1b0a06bd93b0893a7
|
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is the 2014 license.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Please readme:)
|
data/bin/crowdfund
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/top/project'
|
4
|
+
require_relative '../lib/top/fundrequest'
|
5
|
+
|
6
|
+
# project1 = Project.new("LMN", 500, 3000)
|
7
|
+
project2 = Top::Project.new("XYZ", 25, 75)
|
8
|
+
project3 = Top::Project.new("ABC", 300, 700)
|
9
|
+
|
10
|
+
# building = FundRequest.new("Building")
|
11
|
+
studying = Top::FundRequest.new("Studying")
|
12
|
+
|
13
|
+
# building.add_project_to_category(project1)
|
14
|
+
# studying.add_project_to_category(project2)
|
15
|
+
# studying.add_project_to_category(project3)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
default_file_directory = File.join(File.dirname(__FILE__), 'users_projects_csv.csv')
|
21
|
+
studying.load_users_projects(ARGV.shift || default_file_directory )
|
22
|
+
|
23
|
+
|
24
|
+
# puts building.category
|
25
|
+
# puts
|
26
|
+
#
|
27
|
+
# puts studying.category
|
28
|
+
# puts
|
29
|
+
|
30
|
+
|
31
|
+
studying.funding_round(2)
|
32
|
+
|
33
|
+
# loop do
|
34
|
+
# puts "No of rounds? (or exit) :"
|
35
|
+
# answer = gets.chomp.downcase
|
36
|
+
# case answer
|
37
|
+
# when "exit"
|
38
|
+
# break
|
39
|
+
# when /^\d+$/
|
40
|
+
# # building.funding_round(answer.to_i)
|
41
|
+
# # puts
|
42
|
+
# studying.funding_round(answer.to_i)
|
43
|
+
# puts
|
44
|
+
# else
|
45
|
+
# puts "Try again."
|
46
|
+
# end
|
47
|
+
# studying.save_summary_to_text_file
|
48
|
+
# end
|
49
|
+
|
50
|
+
studying.save_summary_to_text_file
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
# projects = []
|
61
|
+
# projects = [project1, project2, project3]
|
62
|
+
#
|
63
|
+
# puts "Number of projects: #{projects.size}"
|
64
|
+
#
|
65
|
+
# puts
|
66
|
+
#
|
67
|
+
# projects.each do |project|
|
68
|
+
# puts "Project name: #{project.name}"
|
69
|
+
# puts "Project funding: #{project.funding}"
|
70
|
+
# puts "Project goal: #{project.goal}"
|
71
|
+
# puts "Project gap: #{project.gap}"
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# puts
|
75
|
+
#
|
76
|
+
# projects.each do |project|
|
77
|
+
# puts "Project #{project.name} has a funding goal of $#{project.goal}."
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# puts
|
81
|
+
#
|
82
|
+
# projects.each do |project|
|
83
|
+
# project.drop
|
84
|
+
# project.rise
|
85
|
+
# project.drop
|
86
|
+
# project.drop
|
87
|
+
# puts project
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# puts
|
91
|
+
#
|
92
|
+
# projects.pop
|
93
|
+
# project4 = Project.new("DGE", 900, 4000)
|
94
|
+
# projects.push(project4)
|
95
|
+
# puts projects
|
96
|
+
#
|
97
|
+
# puts
|
98
|
+
#
|
99
|
+
# projects.delete(project1)
|
100
|
+
# puts projects
|
101
|
+
#
|
102
|
+
# puts
|
103
|
+
#
|
104
|
+
# projects << project1
|
105
|
+
# projects.push(project3)
|
106
|
+
# puts projects
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
# puts project1.name
|
123
|
+
# puts project2.name
|
124
|
+
# puts project3.name
|
125
|
+
# puts
|
126
|
+
# puts project1.funding
|
127
|
+
# puts project2.funding
|
128
|
+
# puts project3.funding
|
129
|
+
# puts
|
130
|
+
# puts project1.goal
|
131
|
+
# puts project2.goal
|
132
|
+
# puts project3.goal
|
133
|
+
# puts
|
134
|
+
# puts project1.gap
|
135
|
+
# puts project2.gap
|
136
|
+
# puts project3.gap
|
137
|
+
# puts
|
138
|
+
|
139
|
+
# puts project1.inspect
|
140
|
+
# puts project2.inspect
|
141
|
+
# puts project3.inspect
|
142
|
+
# puts
|
143
|
+
#
|
144
|
+
# puts project1
|
145
|
+
# puts project2
|
146
|
+
# puts project3
|
147
|
+
#
|
148
|
+
# project1.drop
|
149
|
+
# project2.rise
|
150
|
+
# puts project1
|
151
|
+
# puts project2
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
# def time
|
157
|
+
# current_time = Time.new
|
158
|
+
# current_time.strftime("%H:%M%P, %A,%e of %B, %Y")
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# def projects(name, funding=0)
|
162
|
+
# "Project #{name} has a funding of AUD #{funding}. Last updated: #{time}."
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
# puts projects("ABC", 1000)
|
166
|
+
# puts projects("LMN")
|
167
|
+
# puts projects("XYZ", 2300)
|
168
|
+
# puts projects("TBD", 800)
|
169
|
+
|
170
|
+
|
171
|
+
# project1 = "Project ABC"
|
172
|
+
# project2 = "Project LMN"
|
173
|
+
# project3 = "Project XYZ"
|
174
|
+
#
|
175
|
+
# funding1 = 1000
|
176
|
+
# funding2 = 800
|
177
|
+
# funding3 = 2300
|
178
|
+
#
|
179
|
+
# puts "#{project1} has $#{funding1} in funding.\n\n"
|
180
|
+
# puts "Projects:\n\t#{project1}\n\t#{project2}\n\t#{project3}"
|
181
|
+
#
|
182
|
+
# puts "#{project1.ljust(20, '.')} AUD #{funding1} of available funding."
|
183
|
+
# puts "#{project2.ljust(20, '.')} AUD #{funding2} of available funding."
|
184
|
+
# puts "#{project3.ljust(20, '.')} AUD #{funding3} of available funding."
|
185
|
+
|
186
|
+
|
187
|
+
# puts "#{project1.ljust(30, '- - ')} available funding: AUD #{funding1}."
|
188
|
+
# puts "#{project2.capitalize.center(30, '^')} with AUD #{funding2.to_s.rjust(20, '>')} funding."
|
189
|
+
# puts "#{project3.upcase} has funding of AUD #{funding3}."
|
190
|
+
|
191
|
+
# current_time = Time.new
|
192
|
+
# formatted_time = current_time.strftime("%A %m/%d/%Y at %I:%M%p")
|
193
|
+
# puts "Funding amounts as of #{formatted_time}."
|
data/bin/save.txt
ADDED
data/lib/top/dieroll.rb
ADDED
data/lib/top/fundable.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fundable
|
2
|
+
|
3
|
+
def drop
|
4
|
+
self.funding -= 150
|
5
|
+
puts "Project #{self.name} lost some (150) funds!"
|
6
|
+
end
|
7
|
+
|
8
|
+
def rise
|
9
|
+
self.funding += 250
|
10
|
+
puts "Project #{self.name} got more (250) funds!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def gap
|
14
|
+
self.goal - self.funding
|
15
|
+
end
|
16
|
+
|
17
|
+
def fully_funded?
|
18
|
+
gap <= 0
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
require_relative 'dieroll'
|
3
|
+
|
4
|
+
module Top
|
5
|
+
module FundingRound
|
6
|
+
|
7
|
+
def self.funding_round(project)
|
8
|
+
new_die_object = DieRoll.new
|
9
|
+
number = new_die_object.roll
|
10
|
+
if number.odd?
|
11
|
+
project.drop
|
12
|
+
else
|
13
|
+
project.rise
|
14
|
+
end
|
15
|
+
sample_pledge = PledgePool::random
|
16
|
+
puts "Project #{project.name} received a #{sample_pledge.name} pledge worth $#{sample_pledge.amount}.\n"
|
17
|
+
|
18
|
+
project.collecting_pledges(sample_pledge)
|
19
|
+
project.add_pledge(sample_pledge)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
# require_relative 'dieroll'
|
3
|
+
require_relative 'fundinground'
|
4
|
+
require_relative 'pledge'
|
5
|
+
|
6
|
+
|
7
|
+
module Top
|
8
|
+
class FundRequest
|
9
|
+
|
10
|
+
attr_reader :category, :fully_funded, :under_funded
|
11
|
+
|
12
|
+
def initialize(category)
|
13
|
+
@category = category
|
14
|
+
@container = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_project_to_category(project)
|
18
|
+
@container << project
|
19
|
+
end
|
20
|
+
|
21
|
+
#--------------------------------------------
|
22
|
+
# two ways of loading projects from csv file.
|
23
|
+
#--------------------------------------------
|
24
|
+
#--------------------------------------------
|
25
|
+
# first way
|
26
|
+
#--------------------------------------------
|
27
|
+
|
28
|
+
# def load_users_projects(from_file)
|
29
|
+
# CSV.foreach(from_file) do |row|
|
30
|
+
# project = Project.new(row[0], row[1].to_i, row[2].to_i)
|
31
|
+
# add_project_to_category(project)
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
|
35
|
+
#--------------------------------------------
|
36
|
+
# second way - first half. Second half in project.rb
|
37
|
+
#--------------------------------------------
|
38
|
+
|
39
|
+
def load_users_projects(from_file)
|
40
|
+
File.readlines(from_file).each do |line|
|
41
|
+
add_project_to_category(Project.from_csv(line))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
#--------------------------------------------
|
46
|
+
#--------------------------------------------
|
47
|
+
|
48
|
+
def funding_round(round)
|
49
|
+
puts "Project category: #{@category}"
|
50
|
+
|
51
|
+
@container.each do |project|
|
52
|
+
puts project
|
53
|
+
end
|
54
|
+
|
55
|
+
PledgePool::lists_pledge_options
|
56
|
+
|
57
|
+
1.upto(round) do |round|
|
58
|
+
puts "\nRound: #{round} of funding:"
|
59
|
+
|
60
|
+
@container.each do |project|
|
61
|
+
FundingRound.funding_round(project)
|
62
|
+
|
63
|
+
# B
|
64
|
+
project.each_received_pledge do |pledge|
|
65
|
+
puts "$#{pledge.amount} in #{pledge.name} pledges"
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "#{project.funding} GRAND TOTAL amount\n\n"
|
69
|
+
|
70
|
+
puts project
|
71
|
+
end
|
72
|
+
end
|
73
|
+
print_summary
|
74
|
+
end
|
75
|
+
|
76
|
+
def print_project_data(project)
|
77
|
+
"achieved #{project.funding} funding out of #{project.goal} goal"
|
78
|
+
end
|
79
|
+
|
80
|
+
def fully_funded
|
81
|
+
@container.select{|project| project.fully_funded?}
|
82
|
+
end
|
83
|
+
|
84
|
+
def under_funded
|
85
|
+
@container.reject{|project| project.fully_funded?}
|
86
|
+
end
|
87
|
+
|
88
|
+
def print_summary
|
89
|
+
puts "\nFully funded projects:"
|
90
|
+
fully_funded.each do |project|
|
91
|
+
fully_funded = "Project: #{project.name}".ljust(25, '.')
|
92
|
+
puts "#{fully_funded} #{print_project_data(project)}"
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "\nUnderfunded projects:"
|
96
|
+
under_funded.each do |project|
|
97
|
+
under_funded = "Project: #{project.name}".ljust(25, '.')
|
98
|
+
puts "#{under_funded} #{print_project_data(project)}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def save_summary_to_text_file(to_file="save.txt")
|
103
|
+
File.open(to_file, "w") do |file|
|
104
|
+
file.puts "Projects that still need funding (underfunded):"
|
105
|
+
under_funded.each do |project|
|
106
|
+
file.puts "Project #{project.name} - #{print_project_data(project)}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
if __FILE__ == $0
|
115
|
+
project4 = Project.new("aaa", 500, 1000)
|
116
|
+
project5 = Project.new("bbb", 750, 1500)
|
117
|
+
category3 = FundRequest.new("Self-study")
|
118
|
+
category3.add_project_to_category(project4)
|
119
|
+
category3.add_project_to_category(project5)
|
120
|
+
|
121
|
+
|
122
|
+
category3.funding_round(3)
|
123
|
+
|
124
|
+
category3.save_summary_to_text_file
|
125
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
|
3
|
+
module Top
|
4
|
+
class GrantProject < Project
|
5
|
+
|
6
|
+
def drop
|
7
|
+
puts "Nu, nu - Project #{@name} can not loose any funds!"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
if __FILE__ == $0
|
14
|
+
grant = GrantProject.new("Grant", 500, 1000)
|
15
|
+
non_grant = Project.new("NonGrant", 500, 1000)
|
16
|
+
|
17
|
+
puts grant.funding
|
18
|
+
puts non_grant.funding
|
19
|
+
grant.rise
|
20
|
+
non_grant.rise
|
21
|
+
grant.drop
|
22
|
+
non_grant.drop
|
23
|
+
puts grant.funding
|
24
|
+
puts non_grant.funding
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'project'
|
2
|
+
require 'mathn'
|
3
|
+
|
4
|
+
module Top
|
5
|
+
class MatchProject < Project
|
6
|
+
|
7
|
+
def rise
|
8
|
+
ratio = ("#{@funding}".to_i / "#{@goal}".to_i) * 1.00
|
9
|
+
puts "Ratio of funding to the goal before calling rise: #{ratio}"
|
10
|
+
super
|
11
|
+
ratio = ("#{@funding}".to_i / "#{@goal}".to_i) * 1.00
|
12
|
+
puts "Ratio of funding to the goal after calling rise: #{ratio}"
|
13
|
+
if half_of_funding_secured?(ratio)
|
14
|
+
puts "(+) This project has now #{@funding} in funding, which means that it secured more than 50% of its goal of #{@goal}.\nTherefore, it will get a top up to full!\n"
|
15
|
+
top_up_to_full
|
16
|
+
else
|
17
|
+
puts "(-) Half of funding not secured"
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def half_of_funding_secured?(ratio)
|
23
|
+
puts "Ratio: #{ratio}"
|
24
|
+
ratio >= 0.50
|
25
|
+
end
|
26
|
+
|
27
|
+
def top_up_to_full
|
28
|
+
puts "Project #{@name} got a top up to full of #{gap}!\nand now it has achieved a funding of #{@funding + gap}\nwhich should be equal its goal, namely #{@goal}"
|
29
|
+
@funding += gap
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
if __FILE__ == $0
|
37
|
+
project1 = MatchProject.new("Matching", 0, 1000)
|
38
|
+
2.times{project1.rise}
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
end
|
data/lib/top/pledge.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Top
|
2
|
+
|
3
|
+
Pledge = Struct.new(:name, :amount)
|
4
|
+
|
5
|
+
module PledgePool
|
6
|
+
|
7
|
+
PLEDGES = [
|
8
|
+
Pledge.new(:bronze, 50),
|
9
|
+
Pledge.new(:silver, 75),
|
10
|
+
Pledge.new(:gold, 100)
|
11
|
+
]
|
12
|
+
|
13
|
+
def self.lists_pledge_options
|
14
|
+
pledge_options = PledgePool::PLEDGES
|
15
|
+
puts "\nThere are #{pledge_options.size} possible pledge amounts:\n"
|
16
|
+
|
17
|
+
pledge_options.each do |option|
|
18
|
+
puts "\tA #{option.name} pledge is worth $#{option.amount}."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.random
|
23
|
+
PLEDGES.sample
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
if __FILE__ == $0
|
31
|
+
puts PledgePool::PLEDGES[2].name
|
32
|
+
|
33
|
+
PledgePool::lists_pledge_options
|
34
|
+
|
35
|
+
puts PledgePool::random.name
|
36
|
+
|
37
|
+
end
|
data/lib/top/project.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# require_relative 'fundrequest'
|
2
|
+
require_relative 'pledge'
|
3
|
+
require 'csv'
|
4
|
+
require_relative 'fundable'
|
5
|
+
|
6
|
+
module Top
|
7
|
+
class Project
|
8
|
+
include Fundable
|
9
|
+
|
10
|
+
attr_accessor :name
|
11
|
+
attr_accessor :funding
|
12
|
+
attr_reader :goal
|
13
|
+
|
14
|
+
def initialize(name, funding=0, goal)
|
15
|
+
@name = name
|
16
|
+
@funding = funding
|
17
|
+
@goal = goal
|
18
|
+
@pledges = Hash.new(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"Project #{@name} has $#{@funding} in funding towards a goal of $#{@goal}. So the remaining gap is #{gap}."
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def collecting_pledges(sample_pledge)
|
28
|
+
@pledges[sample_pledge.name] += sample_pledge.amount
|
29
|
+
puts "Project #{@name}'s pledges: #{@pledges}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_pledge(sample_pledge)
|
33
|
+
@funding += sample_pledge.amount
|
34
|
+
|
35
|
+
# puts "Project #{@name} received a #{sample_pledge.name} pledge worth #{sample_pledge.amount}."
|
36
|
+
end
|
37
|
+
|
38
|
+
# A
|
39
|
+
|
40
|
+
def each_received_pledge
|
41
|
+
@pledges.each do |name, amount|
|
42
|
+
yield Pledge.new(name, amount)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
#--------------------------------------------
|
48
|
+
# second way - second half. First half in fundrequest.rb
|
49
|
+
#--------------------------------------------
|
50
|
+
|
51
|
+
def self.from_csv(string)
|
52
|
+
name, funding, goal = string.split(',')
|
53
|
+
new(name, Integer(funding), Integer(goal))
|
54
|
+
end
|
55
|
+
|
56
|
+
#--------------------------------------------
|
57
|
+
#--------------------------------------------
|
58
|
+
|
59
|
+
|
60
|
+
# def practice
|
61
|
+
# @pledges.each do |key, value|
|
62
|
+
# puts "$#{value} in #{key} pledges"
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
if __FILE__ == $0
|
71
|
+
project4 = Project.new("aaa", 500, 1000)
|
72
|
+
project5 = Project.new("bbb", 750, 1500)
|
73
|
+
project4.rise
|
74
|
+
project5.rise
|
75
|
+
project4.drop
|
76
|
+
project5.drop
|
77
|
+
project4.rise
|
78
|
+
project5.rise
|
79
|
+
puts project4
|
80
|
+
puts project5
|
81
|
+
puts project4.funding
|
82
|
+
puts project5.funding
|
83
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'top/fundrequest'
|
2
|
+
|
3
|
+
module Top
|
4
|
+
describe FundRequest do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@project9 = Project.new("Dog lovers", 600, 1000)
|
8
|
+
@category3 = FundRequest.new("Petlovers")
|
9
|
+
@category3.add_project_to_category(@project9)
|
10
|
+
|
11
|
+
$stdout = StringIO.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "rises funds of a project by 250 if die roll number is even." do
|
15
|
+
DieRoll.any_instance.stub(:roll).and_return(4)
|
16
|
+
|
17
|
+
@category3.funding_round1
|
18
|
+
|
19
|
+
@project9.funding.should == (600 + 250)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "drops funds of a project by 150 if die roll number is odd" do
|
23
|
+
DieRoll.any_instance.stub(:roll).and_return(5)
|
24
|
+
|
25
|
+
@category3.funding_round1
|
26
|
+
|
27
|
+
@project9.funding.should == (600 - 150)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
#
|
38
|
+
# @project11 = Project.new("Mouse lovers", 500, 1000)
|
39
|
+
|
40
|
+
# @category3.add_project_to_category(@project10)
|
41
|
+
# @category3.add_project_to_category(@project11)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'top/pledge'
|
2
|
+
|
3
|
+
module Top
|
4
|
+
describe Pledge do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@pledge = Pledge.new(:bronze, 50)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name attribute" do
|
11
|
+
@pledge.name.should == :bronze
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has an ammount attribute" do
|
15
|
+
@pledge.amount.should == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe PledgePool do
|
22
|
+
|
23
|
+
it "has 3 pledge options" do
|
24
|
+
PledgePool::PLEDGES.size == 3
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a bronze pledge worth 50" do
|
28
|
+
PledgePool::PLEDGES[0].should == Pledge.new(:bronze, 50)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a silver pledge worth 75" do
|
32
|
+
PledgePool::PLEDGES[1].should == Pledge.new(:silver, 75)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a gold pledge worth 100" do
|
36
|
+
PledgePool::PLEDGES[2].should == Pledge.new(:gold, 100)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns a random pledge" do
|
40
|
+
sample_pledge = PledgePool::random
|
41
|
+
PledgePool::PLEDGES.should include(sample_pledge)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'top/project'
|
2
|
+
require 'top/fundrequest'
|
3
|
+
|
4
|
+
module Top
|
5
|
+
describe Project do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@project7 = Project.new("SPC", 200, 800)
|
9
|
+
@project8 = Project.new("SPD", 900)
|
10
|
+
$stdout = StringIO.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has an initial target funding amount" do
|
14
|
+
@project7.funding.should == 200
|
15
|
+
end
|
16
|
+
|
17
|
+
it "computes the total funding outstanding as the target funding amount minut the funding amount." do
|
18
|
+
@project7.gap.should == 600
|
19
|
+
end
|
20
|
+
|
21
|
+
it "increases funds by 250 when funds are added." do
|
22
|
+
@project7.rise
|
23
|
+
@project7.funding.should == 450
|
24
|
+
end
|
25
|
+
|
26
|
+
it "decreases funds by 150 when funds are removed." do
|
27
|
+
@project7.drop
|
28
|
+
@project7.funding.should == 50
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a default value of 0 for funding amount." do
|
32
|
+
@project8.funding.should == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
#or for the last one:
|
36
|
+
|
37
|
+
context "created without a funding amount." do
|
38
|
+
before do
|
39
|
+
@project7 = Project.new("SPD", 900)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a default value of 0 for funding amount." do
|
43
|
+
@project7.funding.should == 0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when fully funded" do
|
48
|
+
before do
|
49
|
+
@project10 = Project.new("Catlovers", 800, 1000)
|
50
|
+
@category3 = FundRequest.new("Petlovers")
|
51
|
+
@category3.add_project_to_category(@project10)
|
52
|
+
|
53
|
+
$stdout = StringIO.new
|
54
|
+
end
|
55
|
+
|
56
|
+
it "gives a notification that a project has been fully funded." do
|
57
|
+
DieRoll.any_instance.stub(:roll).and_return(4)
|
58
|
+
|
59
|
+
@category3.funding_round1
|
60
|
+
|
61
|
+
@project10.should be_fully_funded
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when under funded" do
|
66
|
+
before do
|
67
|
+
@project10 = Project.new("Catlovers", 800, 1000)
|
68
|
+
@category3 = FundRequest.new("Petlovers")
|
69
|
+
@category3.add_project_to_category(@project10)
|
70
|
+
|
71
|
+
$stdout = StringIO.new
|
72
|
+
end
|
73
|
+
|
74
|
+
it "gives notification that a project still needs funds" do
|
75
|
+
DieRoll.any_instance.stub(:roll).and_return(3)
|
76
|
+
|
77
|
+
@category3.funding_round1
|
78
|
+
|
79
|
+
@project10.should_not be_fully_funded
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crowdfund_mike_brooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Brooks
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-23 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: Please readme:)
|
28
|
+
email: brooksbrisbane@gmail.com
|
29
|
+
executables:
|
30
|
+
- crowdfund
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README
|
36
|
+
- bin/crowdfund
|
37
|
+
- bin/save.txt
|
38
|
+
- bin/users_projects_csv.csv
|
39
|
+
- lib/top/dieroll.rb
|
40
|
+
- lib/top/fundable.rb
|
41
|
+
- lib/top/fundinground.rb
|
42
|
+
- lib/top/fundrequest.rb
|
43
|
+
- lib/top/grant_project.rb
|
44
|
+
- lib/top/match_project.rb
|
45
|
+
- lib/top/pledge.rb
|
46
|
+
- lib/top/project.rb
|
47
|
+
- spec/top/fundrequest_spec.rb
|
48
|
+
- spec/top/pledge_spec.rb
|
49
|
+
- spec/top/project_spec.rb
|
50
|
+
homepage: http://www.brooksmike.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.2.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: testing creating a gem
|
74
|
+
test_files:
|
75
|
+
- spec/top/fundrequest_spec.rb
|
76
|
+
- spec/top/pledge_spec.rb
|
77
|
+
- spec/top/project_spec.rb
|