prag_studio_fund 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 +7 -0
- data/README +63 -0
- data/bin/crowdfund +32 -0
- data/bin/projects.csv +3 -0
- data/bin/projects.txt +5 -0
- data/lib/crowdfund/die.rb +13 -0
- data/lib/crowdfund/fundable.rb +21 -0
- data/lib/crowdfund/funding_round.rb +19 -0
- data/lib/crowdfund/fundrequest.rb +107 -0
- data/lib/crowdfund/grant_project.rb +11 -0
- data/lib/crowdfund/matching_project.rb +19 -0
- data/lib/crowdfund/pledge_pool.rb +15 -0
- data/lib/crowdfund/project.rb +43 -0
- data/spec/crowdfund/fundrequest_spec.rb +39 -0
- data/spec/crowdfund/grant_project_spec.rb +22 -0
- data/spec/crowdfund/matching_project_spec.rb +25 -0
- data/spec/crowdfund/pledge_pool_spec.rb +44 -0
- data/spec/crowdfund/project_spec.rb +111 -0
- data/spec/crowdfund/spec_helper.rb +10 -0
- metadata +146 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: d608bddf02f308eb2f445610ac0f0a87a5ff5199
|
|
4
|
+
data.tar.gz: 6b115935b27c181c5ee0b4cb56dd46735dbb18d5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b52f87c6fda89371d96b47c5ae89bfd642469a1a8e0d01d12570591fb047c8aef178f6f1455b79460b1112ee54b58f330ccae456c6be03b034416efd1cd4f4ee
|
|
7
|
+
data.tar.gz: 4a319f1b5d2d2b1bc116a854cbf9b98cd89a3a4e95a859d08a47d8efb21484bc7c207fdac2c9884bf0e527a80b3293d66827050682690bd8c6350d4b995f661d
|
data/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2016 Waihon Yew
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Crowdfund is a Ruby program developed based on Pragmatic Studio's Ruby Programming hands-on video course, and distributed as a Ruby gem.
|
|
2
|
+
|
|
3
|
+
This program has been developed using all the strengths of Ruby including the following.
|
|
4
|
+
|
|
5
|
+
Ruby Programming Environment
|
|
6
|
+
* Installing Ruby on your favorite operating system (free exercise)
|
|
7
|
+
* Running Ruby using the interactive Ruby shell (irb) and writing Ruby program files
|
|
8
|
+
* Using Ruby's documentation system to get help
|
|
9
|
+
* Installing external Ruby libraries using RubyGems
|
|
10
|
+
* Troubleshooting common problems
|
|
11
|
+
|
|
12
|
+
Ruby Language Constructs
|
|
13
|
+
* Expressions and variables
|
|
14
|
+
* Numbers, string, and symbols (free video & exercise)
|
|
15
|
+
* Loops and conditional expressions
|
|
16
|
+
* Arrays and hashes (free video & exercise on hashes)
|
|
17
|
+
* Classes, modules, and structs
|
|
18
|
+
|
|
19
|
+
Object-Oriented Programming
|
|
20
|
+
* Using built-in Ruby classes
|
|
21
|
+
* Defining your own classes with state and behavior (free video & exercise)
|
|
22
|
+
* Creating unique objects
|
|
23
|
+
* Telling objects what to do by calling methods
|
|
24
|
+
* Modeling class-level inheritance relationships
|
|
25
|
+
* Sharing code with mixins
|
|
26
|
+
|
|
27
|
+
Object-Oriented Design Principles
|
|
28
|
+
* Encapsulation
|
|
29
|
+
* Separation of concerns
|
|
30
|
+
* Polymorphism
|
|
31
|
+
* Don't Repeat Yourself
|
|
32
|
+
* Tell, Don't Ask
|
|
33
|
+
|
|
34
|
+
Blocks and Iterators
|
|
35
|
+
* Calling built-in methods that take blocks
|
|
36
|
+
* Writing your own methods that yield to blocks
|
|
37
|
+
* Implementing custom iterators
|
|
38
|
+
* Effectively using blocks in your programs
|
|
39
|
+
|
|
40
|
+
Organizing Ruby Code
|
|
41
|
+
* Creating a Ruby project structure
|
|
42
|
+
* Separating source files for easier reuse and testing
|
|
43
|
+
* Namespacing to avoid naming clashes
|
|
44
|
+
|
|
45
|
+
* Input/Output
|
|
46
|
+
* Reading data from files
|
|
47
|
+
* Writing data to files
|
|
48
|
+
* Creating an interactive console prompt
|
|
49
|
+
* Handling command-line input
|
|
50
|
+
|
|
51
|
+
Unit Testing
|
|
52
|
+
* Writing and running unit tests with RSpec
|
|
53
|
+
* Test-driven development and the red-green-refactor cycle
|
|
54
|
+
* Stubbing methods to control tests
|
|
55
|
+
* Refactoring code, safely!
|
|
56
|
+
|
|
57
|
+
Distribution
|
|
58
|
+
* Conforming to RubyGems conventions
|
|
59
|
+
* Writing a GemSpec
|
|
60
|
+
* Building a RubyGem
|
|
61
|
+
* Publishing a RubyGem to a public server
|
|
62
|
+
|
|
63
|
+
Ruby Programming Idioms
|
data/bin/crowdfund
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative '../lib/crowdfund/fundrequest'
|
|
3
|
+
require_relative '../lib/crowdfund/project'
|
|
4
|
+
require_relative '../lib/crowdfund/grant_project'
|
|
5
|
+
require_relative '../lib/crowdfund/matching_project'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
vc_friendly = CrowdFund::FundRequest.new("VC-Friendly Start-up Projects")
|
|
9
|
+
default_project_file = File.join(File.dirname(__FILE__), "projects.csv")
|
|
10
|
+
vc_friendly.load_projects(ARGV.shift || default_project_file)
|
|
11
|
+
|
|
12
|
+
grant_project = CrowdFund::GrantProject.new("Project Grant", 1000, 150)
|
|
13
|
+
matching_project = CrowdFund::MatchingProject.new("Projecting Matching", 1500, 300)
|
|
14
|
+
vc_friendly.add_project(grant_project)
|
|
15
|
+
vc_friendly.add_project(matching_project)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
loop do
|
|
19
|
+
puts "\nHow many rounds of funding requests? ('quit' to exit)"
|
|
20
|
+
answer = gets.chomp.downcase
|
|
21
|
+
case answer
|
|
22
|
+
when /^\d+$/ # 1 or more digits
|
|
23
|
+
vc_friendly.request_funding(Integer(answer))
|
|
24
|
+
when 'quit', 'exit'
|
|
25
|
+
vc_friendly.print_stats
|
|
26
|
+
break
|
|
27
|
+
else
|
|
28
|
+
puts "Please enter a number or 'quit'"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
vc_friendly.save_projects
|
data/bin/projects.csv
ADDED
data/bin/projects.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module CrowdFund
|
|
2
|
+
module Fundable
|
|
3
|
+
def add_fund(amount=25)
|
|
4
|
+
self.funding += amount
|
|
5
|
+
puts "\n#{name} got more funds!"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def remove_fund(amount=15)
|
|
9
|
+
self.funding -= amount
|
|
10
|
+
puts "\n#{name} lost some funds!"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def funding_needed
|
|
14
|
+
target_funding - funding
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def fully_funded?
|
|
18
|
+
funding_needed <= 0
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'project'
|
|
3
|
+
|
|
4
|
+
module CrowdFund
|
|
5
|
+
module FundingRound
|
|
6
|
+
def self.take_turn(project)
|
|
7
|
+
die = Die.new
|
|
8
|
+
if die.roll.even?
|
|
9
|
+
project.add_fund
|
|
10
|
+
else
|
|
11
|
+
project.remove_fund
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# pledge = PledgePool.random
|
|
15
|
+
# project.received_pledge(pledge)
|
|
16
|
+
project.received_pledge(PledgePool.random)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'project'
|
|
3
|
+
require_relative 'funding_round'
|
|
4
|
+
require_relative 'pledge_pool'
|
|
5
|
+
require 'csv'
|
|
6
|
+
|
|
7
|
+
module CrowdFund
|
|
8
|
+
class FundRequest
|
|
9
|
+
attr_reader :name
|
|
10
|
+
|
|
11
|
+
def initialize(name)
|
|
12
|
+
@name = name
|
|
13
|
+
@projects = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_project(project)
|
|
17
|
+
@projects << project
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def request_funding(rounds)
|
|
21
|
+
puts "There are #{@projects.size} projects in #{@name}:"
|
|
22
|
+
@projects.each do |project|
|
|
23
|
+
puts project.name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
pledges = PledgePool::PLEDGES
|
|
27
|
+
puts "\nThere are #{pledges.size} possible pledge amounts:"
|
|
28
|
+
pledges.each do |pledge|
|
|
29
|
+
puts "A #{pledge.name} pledge is worth $#{pledge.amount}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
1.upto(rounds) do |n|
|
|
33
|
+
puts "\nRound #{n}:"
|
|
34
|
+
@projects.each do |project|
|
|
35
|
+
FundingRound.take_turn(project)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def print_stats
|
|
41
|
+
@projects.each do |project|
|
|
42
|
+
puts "\n#{project.name}'s pledges:"
|
|
43
|
+
project.each_received_pledge do |pledge|
|
|
44
|
+
puts "$#{pledge.amount} in #{pledge.name} pledges"
|
|
45
|
+
end
|
|
46
|
+
puts "$#{project.total_pledges} in total pledges"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
#fully_funded, under_funded = @projects.partition { |project| project.fully_funded? }
|
|
50
|
+
|
|
51
|
+
puts "\n#{@name} Statistics:"
|
|
52
|
+
|
|
53
|
+
print_fully_funded_projects
|
|
54
|
+
|
|
55
|
+
print_under_funded_projects
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def load_projects(from_file)
|
|
59
|
+
CSV.foreach(from_file) do |row|
|
|
60
|
+
# funding (3rd attribute) is optional
|
|
61
|
+
if row[2].nil?
|
|
62
|
+
project = Project.new(row[0], row[1].to_i)
|
|
63
|
+
else
|
|
64
|
+
project = Project.new(row[0], row[1].to_i, row[2].to_i)
|
|
65
|
+
end
|
|
66
|
+
add_project(project)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def fully_funded_projects
|
|
71
|
+
@projects.select { |project| project.fully_funded? }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def under_funded_projects
|
|
75
|
+
@projects.reject { |project| project.fully_funded? }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def save_projects(to_file="projects.txt")
|
|
79
|
+
File.open(to_file, "w") do |file|
|
|
80
|
+
print_under_funded_projects(file)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def print_fully_funded_projects(file=$stdout)
|
|
87
|
+
prefix = "\n" if file == $stdout
|
|
88
|
+
file.puts "#{prefix}#{fully_funded_projects.size} fully-funded projects:"
|
|
89
|
+
fully_funded_projects.each do |project|
|
|
90
|
+
print_name_and_funding(project, file)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def print_under_funded_projects(file=$stdout)
|
|
95
|
+
prefix = "\n" if file == $stdout
|
|
96
|
+
file.puts "#{prefix}#{under_funded_projects.size} under-funded projects:"
|
|
97
|
+
under_funded_projects.sort.each do |project|
|
|
98
|
+
print_name_and_funding(project, file)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def print_name_and_funding(project, file=$stdout)
|
|
103
|
+
file.puts "#{project.name} (#{project.funding_needed})"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require_relative 'project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
class MatchingProject < Project
|
|
5
|
+
def add_fund(amount=25)
|
|
6
|
+
amount = (amount * 2) if secured_half_funding?
|
|
7
|
+
super(amount)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def half_funding
|
|
11
|
+
@target_funding / 2.0
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def secured_half_funding?
|
|
15
|
+
@funding >= half_funding
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative 'fundable'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
class Project
|
|
5
|
+
include Fundable
|
|
6
|
+
|
|
7
|
+
attr_accessor :name
|
|
8
|
+
attr_accessor :funding
|
|
9
|
+
attr_reader :target_funding
|
|
10
|
+
|
|
11
|
+
def initialize(name, target_funding, funding=0)
|
|
12
|
+
@name = name
|
|
13
|
+
@target_funding = target_funding
|
|
14
|
+
@funding = funding
|
|
15
|
+
@pledges_received = Hash.new(0)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_s
|
|
19
|
+
"#{@name} has $#{@funding} in funding towards a goal of $#{@target_funding}, i.e. $#{funding_needed} is still needed."
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def <=>(other)
|
|
23
|
+
other.funding_needed <=> funding_needed
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def received_pledge(pledge)
|
|
27
|
+
@pledges_received[pledge.name] += pledge.amount
|
|
28
|
+
@funding += pledge.amount
|
|
29
|
+
puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.amount}."
|
|
30
|
+
puts "#{@name}'s pledges: #{@pledges_received}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def each_received_pledge
|
|
34
|
+
@pledges_received.each do |name, amount|
|
|
35
|
+
yield Pledge.new(name, amount)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def total_pledges
|
|
40
|
+
@pledges_received.values.reduce(0, :+)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'crowdfund/spec_helper'
|
|
2
|
+
require 'crowdfund/fundrequest'
|
|
3
|
+
require 'crowdfund/project'
|
|
4
|
+
require 'crowdfund/die'
|
|
5
|
+
|
|
6
|
+
module CrowdFund
|
|
7
|
+
describe FundRequest do
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
@fundrequest = FundRequest.new("VC-Friendly Start-up Projects")
|
|
11
|
+
|
|
12
|
+
@initial_funding = 100
|
|
13
|
+
@project = Project.new("Project XYZ", 1000, @initial_funding)
|
|
14
|
+
|
|
15
|
+
@fundrequest.add_project(@project)
|
|
16
|
+
|
|
17
|
+
$stdout = StringIO.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "add funds to the project if an even number is rolled" do
|
|
21
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(4)
|
|
22
|
+
allow(PledgePool).to receive(:random).and_return(Pledge.new(:silver, 75))
|
|
23
|
+
|
|
24
|
+
@fundrequest.request_funding(3)
|
|
25
|
+
|
|
26
|
+
expect(@project.funding).to eq(@initial_funding + (3 * (25 + 75)))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "remove funds from the project if an odd number is rolled" do
|
|
30
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
|
31
|
+
allow(PledgePool).to receive(:random).and_return(Pledge.new(:gold, 100))
|
|
32
|
+
|
|
33
|
+
@fundrequest.request_funding(3)
|
|
34
|
+
|
|
35
|
+
expect(@project.funding).to eq(@initial_funding + (3 * (100 - 15)))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'crowdfund/grant_project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe GrantProject do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@target_funding = 1000
|
|
8
|
+
@initial_funding = 100
|
|
9
|
+
@project = GrantProject.new("Grant Project", @target_funding, @initial_funding)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "does not allow funds to be removed" do
|
|
13
|
+
@project.add_fund(150)
|
|
14
|
+
|
|
15
|
+
expect(@project.funding).to eq(@initial_funding + 150)
|
|
16
|
+
|
|
17
|
+
@project.remove_fund(75)
|
|
18
|
+
|
|
19
|
+
expect(@project.funding).to eq(@initial_funding + 150)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'crowdfund/matching_project'
|
|
2
|
+
|
|
3
|
+
module CrowdFund
|
|
4
|
+
describe MatchingProject do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@target_funding = 1000
|
|
8
|
+
@initial_funding = 100
|
|
9
|
+
@project = MatchingProject.new("Matching Project", @target_funding, @initial_funding)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "does not receive matching funds before getting half of its funding secured" do
|
|
13
|
+
@project.add_fund(@project.half_funding - @initial_funding - 1)
|
|
14
|
+
|
|
15
|
+
expect(@project.secured_half_funding?).to be_falsey
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "receives matching funds after getting half of its funding secured" do
|
|
19
|
+
@project.add_fund(@project.half_funding - @initial_funding)
|
|
20
|
+
|
|
21
|
+
expect(@project.secured_half_funding?).to be_truthy
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'crowdfund/spec_helper'
|
|
2
|
+
require 'crowdfund/pledge_pool'
|
|
3
|
+
|
|
4
|
+
module CrowdFund
|
|
5
|
+
describe Pledge do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@pledge = Pledge.new(:silver, 75)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "has a name attribute" do
|
|
12
|
+
expect(@pledge.name).to eq(:silver)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "has an amount attribute" do
|
|
16
|
+
expect(@pledge.amount).to eq(75)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "PledgePool" do
|
|
22
|
+
it "has three pledges" do
|
|
23
|
+
expect(PledgePool::PLEDGES.size).to eq(3)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "has a bronze pledge worth $50" do
|
|
27
|
+
expect(PledgePool::PLEDGES[0]).to eq(Pledge.new(:bronze, 50))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "has a silver pledge worth $75" do
|
|
31
|
+
expect(PledgePool::PLEDGES[1]).to eq(Pledge.new(:silver, 75))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "has a gold pledge worth $100" do
|
|
35
|
+
expect(PledgePool::PLEDGES[2]).to eq(Pledge.new(:gold, 100))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "return a random pledge" do
|
|
39
|
+
pledge = PledgePool.random
|
|
40
|
+
|
|
41
|
+
expect(PledgePool::PLEDGES).to include(pledge)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require 'crowdfund/spec_helper'
|
|
2
|
+
require 'crowdfund/project'
|
|
3
|
+
require 'crowdfund/pledge_pool'
|
|
4
|
+
|
|
5
|
+
module CrowdFund
|
|
6
|
+
describe Project do
|
|
7
|
+
before do
|
|
8
|
+
@target_funding = 1000
|
|
9
|
+
@initial_funding = 100
|
|
10
|
+
@project = Project.new("Project XYZ", @target_funding, @initial_funding)
|
|
11
|
+
$stdout = StringIO.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "has an initial target funding amount" do
|
|
15
|
+
expect(@project.target_funding).to eq(@target_funding)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "computes the total funding outstanding as the target funding amount minus the funding amount" do
|
|
19
|
+
expect(@project.funding_needed).to eq(@target_funding - @initial_funding)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "increases funds by 25 when funds are added" do
|
|
23
|
+
@project.add_fund
|
|
24
|
+
|
|
25
|
+
expect(@project.funding).to eq(@initial_funding + 25)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "decreases funds by 15 when funds are removed" do
|
|
29
|
+
@project.remove_fund
|
|
30
|
+
|
|
31
|
+
expect(@project.funding).to eq(@initial_funding - 15)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "with a default funding" do
|
|
35
|
+
before do
|
|
36
|
+
@target_funding = 1000
|
|
37
|
+
@project = Project.new("Project XYZ", @target_funding)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "has a default value of 0 for funding amount" do
|
|
41
|
+
expect(@project.funding).to eq(0)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "with sufficient funding" do
|
|
46
|
+
before do
|
|
47
|
+
@target_funding = 1000
|
|
48
|
+
@initial_funding = 100
|
|
49
|
+
@project = Project.new("Project XYZ", @target_funding, @initial_funding)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "is fully funded" do
|
|
53
|
+
@project.add_fund(@target_funding - @initial_funding)
|
|
54
|
+
|
|
55
|
+
expect(@project).to be_fully_funded
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "with insufficient funding" do
|
|
60
|
+
before do
|
|
61
|
+
@target_funding = 1000
|
|
62
|
+
@initial_funding = 100
|
|
63
|
+
@project = Project.new("Project XYZ", @target_funding, @initial_funding)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "is not fully funded" do
|
|
67
|
+
@project.add_fund(@target_funding - @initial_funding - 1)
|
|
68
|
+
|
|
69
|
+
expect(@project).not_to be_fully_funded
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "computes total pledges as the sum of all pledge amount" do
|
|
74
|
+
expect(@project.total_pledges).to be_zero
|
|
75
|
+
|
|
76
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
77
|
+
|
|
78
|
+
expect(@project.total_pledges).to eq(50)
|
|
79
|
+
|
|
80
|
+
@project.received_pledge(Pledge.new(:silver, 75))
|
|
81
|
+
|
|
82
|
+
expect(@project.total_pledges).to eq(125)
|
|
83
|
+
|
|
84
|
+
@project.received_pledge(Pledge.new(:gold, 100))
|
|
85
|
+
|
|
86
|
+
expect(@project.total_pledges).to eq(225)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "yields each pledge received and its total pledges" do
|
|
90
|
+
@project.received_pledge(Pledge.new(:gold, 100))
|
|
91
|
+
@project.received_pledge(Pledge.new(:gold, 100))
|
|
92
|
+
@project.received_pledge(Pledge.new(:silver, 75))
|
|
93
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
94
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
95
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
96
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
97
|
+
@project.received_pledge(Pledge.new(:bronze, 50))
|
|
98
|
+
|
|
99
|
+
yielded = []
|
|
100
|
+
@project.each_received_pledge do |pledge|
|
|
101
|
+
yielded << pledge
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
expect(yielded).to eq([
|
|
105
|
+
Pledge.new(:gold, 200),
|
|
106
|
+
Pledge.new(:silver, 75),
|
|
107
|
+
Pledge.new(:bronze, 250)
|
|
108
|
+
])
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: prag_studio_fund
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Waihon Yew
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-09-28 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: '3.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.5'
|
|
27
|
+
description: |
|
|
28
|
+
Crowdfund is a Ruby program developed based on Pragmatic Studio's Ruby Programming hands-on video course, and distributed as a Ruby gem.
|
|
29
|
+
|
|
30
|
+
This program has been developed using all the strengths of Ruby including the following.
|
|
31
|
+
|
|
32
|
+
Ruby Programming Environment
|
|
33
|
+
* Installing Ruby on your favorite operating system (free exercise)
|
|
34
|
+
* Running Ruby using the interactive Ruby shell (irb) and writing Ruby program files
|
|
35
|
+
* Using Ruby's documentation system to get help
|
|
36
|
+
* Installing external Ruby libraries using RubyGems
|
|
37
|
+
* Troubleshooting common problems
|
|
38
|
+
|
|
39
|
+
Ruby Language Constructs
|
|
40
|
+
* Expressions and variables
|
|
41
|
+
* Numbers, string, and symbols (free video & exercise)
|
|
42
|
+
* Loops and conditional expressions
|
|
43
|
+
* Arrays and hashes (free video & exercise on hashes)
|
|
44
|
+
* Classes, modules, and structs
|
|
45
|
+
|
|
46
|
+
Object-Oriented Programming
|
|
47
|
+
* Using built-in Ruby classes
|
|
48
|
+
* Defining your own classes with state and behavior (free video & exercise)
|
|
49
|
+
* Creating unique objects
|
|
50
|
+
* Telling objects what to do by calling methods
|
|
51
|
+
* Modeling class-level inheritance relationships
|
|
52
|
+
* Sharing code with mixins
|
|
53
|
+
|
|
54
|
+
Object-Oriented Design Principles
|
|
55
|
+
* Encapsulation
|
|
56
|
+
* Separation of concerns
|
|
57
|
+
* Polymorphism
|
|
58
|
+
* Don't Repeat Yourself
|
|
59
|
+
* Tell, Don't Ask
|
|
60
|
+
|
|
61
|
+
Blocks and Iterators
|
|
62
|
+
* Calling built-in methods that take blocks
|
|
63
|
+
* Writing your own methods that yield to blocks
|
|
64
|
+
* Implementing custom iterators
|
|
65
|
+
* Effectively using blocks in your programs
|
|
66
|
+
|
|
67
|
+
Organizing Ruby Code
|
|
68
|
+
* Creating a Ruby project structure
|
|
69
|
+
* Separating source files for easier reuse and testing
|
|
70
|
+
* Namespacing to avoid naming clashes
|
|
71
|
+
|
|
72
|
+
* Input/Output
|
|
73
|
+
* Reading data from files
|
|
74
|
+
* Writing data to files
|
|
75
|
+
* Creating an interactive console prompt
|
|
76
|
+
* Handling command-line input
|
|
77
|
+
|
|
78
|
+
Unit Testing
|
|
79
|
+
* Writing and running unit tests with RSpec
|
|
80
|
+
* Test-driven development and the red-green-refactor cycle
|
|
81
|
+
* Stubbing methods to control tests
|
|
82
|
+
* Refactoring code, safely!
|
|
83
|
+
|
|
84
|
+
Distribution
|
|
85
|
+
* Conforming to RubyGems conventions
|
|
86
|
+
* Writing a GemSpec
|
|
87
|
+
* Building a RubyGem
|
|
88
|
+
* Publishing a RubyGem to a public server
|
|
89
|
+
|
|
90
|
+
Ruby Programming Idioms
|
|
91
|
+
email: yewwaihon@gmail.com
|
|
92
|
+
executables:
|
|
93
|
+
- crowdfund
|
|
94
|
+
extensions: []
|
|
95
|
+
extra_rdoc_files: []
|
|
96
|
+
files:
|
|
97
|
+
- LICENSE
|
|
98
|
+
- README
|
|
99
|
+
- bin/crowdfund
|
|
100
|
+
- bin/projects.csv
|
|
101
|
+
- bin/projects.txt
|
|
102
|
+
- lib/crowdfund/die.rb
|
|
103
|
+
- lib/crowdfund/fundable.rb
|
|
104
|
+
- lib/crowdfund/funding_round.rb
|
|
105
|
+
- lib/crowdfund/fundrequest.rb
|
|
106
|
+
- lib/crowdfund/grant_project.rb
|
|
107
|
+
- lib/crowdfund/matching_project.rb
|
|
108
|
+
- lib/crowdfund/pledge_pool.rb
|
|
109
|
+
- lib/crowdfund/project.rb
|
|
110
|
+
- spec/crowdfund/fundrequest_spec.rb
|
|
111
|
+
- spec/crowdfund/grant_project_spec.rb
|
|
112
|
+
- spec/crowdfund/matching_project_spec.rb
|
|
113
|
+
- spec/crowdfund/pledge_pool_spec.rb
|
|
114
|
+
- spec/crowdfund/project_spec.rb
|
|
115
|
+
- spec/crowdfund/spec_helper.rb
|
|
116
|
+
homepage: https://github.com/waihon/prag_studio_fund
|
|
117
|
+
licenses:
|
|
118
|
+
- MIT
|
|
119
|
+
metadata: {}
|
|
120
|
+
post_install_message:
|
|
121
|
+
rdoc_options: []
|
|
122
|
+
require_paths:
|
|
123
|
+
- lib
|
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
|
+
requirements:
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: '1.9'
|
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
requirements: []
|
|
135
|
+
rubyforge_project:
|
|
136
|
+
rubygems_version: 2.6.4
|
|
137
|
+
signing_key:
|
|
138
|
+
specification_version: 4
|
|
139
|
+
summary: Pragmatic Studio's Ruby Programming's Bonus App.
|
|
140
|
+
test_files:
|
|
141
|
+
- spec/crowdfund/fundrequest_spec.rb
|
|
142
|
+
- spec/crowdfund/grant_project_spec.rb
|
|
143
|
+
- spec/crowdfund/matching_project_spec.rb
|
|
144
|
+
- spec/crowdfund/pledge_pool_spec.rb
|
|
145
|
+
- spec/crowdfund/project_spec.rb
|
|
146
|
+
- spec/crowdfund/spec_helper.rb
|