mfp_fundraising_program 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7754ede7efe3f58bbfaa4a3f806c4eb34612798e
4
+ data.tar.gz: fa0cb7c6042995311db355f46f4e788a66b7cb09
5
+ SHA512:
6
+ metadata.gz: 10c54d48dbe3329b7bdec55a66dd794fed0148b4f371bdf83a7aff4aae9ce05becc8fc863528ec2e71012157f61489ba337ef65c6ba1227b9de9e8c572140b12
7
+ data.tar.gz: 5a71564e9eb2cd031217d60df8ffe3e7a1788dffac3ebec28a3b7d49e64daf0e69edab94a79ffe0bf8f7c96e2e03416b5c4d4130fc2ab895aec44056e745129d
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Marcos Parreiras
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
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
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ This is the project developed following the Pragmatic Studio for Ruby and following the bonus rounds from across exercises.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/fundraising_program/fundrequest'
4
+ require_relative '../lib/fundraising_program/grant_project'
5
+ require_relative '../lib/fundraising_program/half_way_project'
6
+
7
+ # Dados baseados em https://wefunder.me/
8
+ # project1 = Project.new( 'parkav', 669, 700 );
9
+ # project2 = Project.new( 'plate iq', 654, 700 );
10
+ # project3 = Project.new( 'bagaveev', 1128, 1600 );
11
+ # project4 = Project.new( 'flaviar', 2912, 3400 );
12
+
13
+ fund_program1 = FundraisingProgram::FundRequest.new("VC-Friendly Start-up Projects.")
14
+ # fund_program1.load_projects(ARGV.shift || "projects.csv")
15
+ default_projects_file = File.join(File.dirname(__FILE__), 'projects.csv')
16
+ fund_program1.load_projects(ARGV.shift || default_projects_file)
17
+
18
+
19
+ grant_project = FundraisingProgram::GrantProject.new("grant", 200, 2030)
20
+ half_way_project = FundraisingProgram::HalfWayProject.new("half way", 200, 4000)
21
+
22
+
23
+ fund_program1.add_project(grant_project)
24
+ fund_program1.add_project(half_way_project)
25
+
26
+ loop do
27
+ puts "How many rounds? ('quit' to exit)"
28
+ answer = STDIN.gets.chomp.downcase
29
+ case answer
30
+ when /^\d+$/
31
+ puts "Enjoy the #{answer} rounds"
32
+ fund_program1.request_funding(answer.to_i)
33
+ when 'quit', 'exit'
34
+ fund_program1.print_stats
35
+ break
36
+ end
37
+ end
38
+
39
+ fund_program1.save_under_funded_projects("under_fundeds_projects.txt")
@@ -0,0 +1,3 @@
1
+ Project1,100,560
2
+ Project2,500,3010
3
+ Project3,1000,1200
@@ -0,0 +1,5 @@
1
+ Under funded projecs:
2
+ Project1......................110......560
3
+ Project2......................510......3010
4
+ Grant.........................250......2030
5
+ Half way......................250......4000
@@ -0,0 +1,13 @@
1
+ module FundraisingProgram
2
+ class Die
3
+ attr_reader :number
4
+
5
+ def initialize
6
+ roll
7
+ end
8
+
9
+ def roll
10
+ rand(1..5)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module FundraisingProgram
2
+ module Fundable
3
+
4
+ def add_fund
5
+ self.funding += 25
6
+ puts "O projeto #{self.name.upcase} recebeu mais fundos =D."
7
+ end
8
+
9
+ def remove_fund
10
+ self.funding -= 15
11
+ puts "O projeto #{self.name.upcase} perdeu alguns fundos =(."
12
+ end
13
+
14
+ def fully_funded?
15
+ self.total_funds >= self.target_funding
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'project'
2
+ require_relative 'die'
3
+ require_relative 'pledge_pool'
4
+
5
+ module FundraisingProgram
6
+ module FundingRound
7
+ def self.take_turn(project)
8
+ die = Die.new
9
+ number_rolled = die.roll
10
+ case number_rolled
11
+ when 1..2
12
+ project.add_fund
13
+ when 3
14
+ puts "#{project.name} skipped"
15
+ when 4..5
16
+ project.remove_fund
17
+ end
18
+ # puts '----------kkkkk'
19
+ pledge = PledgePool::random
20
+ # puts "\nProject #{project.name} received #{pledge.name} pledge worth $#{pledge.amount}"
21
+
22
+ project.add_pledge(pledge)
23
+ puts "\nProject #{project.name} received #{pledge.name} pledge worth $#{pledge.amount}"
24
+ puts "#{project.name}'s pledges: #{project.pledges_accumulated}"
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,102 @@
1
+ require_relative 'project'
2
+ require_relative 'die'
3
+ require_relative 'funding_round'
4
+ require_relative 'pledge_pool'
5
+
6
+ module FundraisingProgram
7
+ class FundRequest
8
+ attr_accessor :name
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ @projects = []
13
+ end
14
+
15
+ def load_projects(from_file)
16
+ File.readlines(from_file).each do |line|
17
+ add_project(Project.from_csv(line))
18
+ end
19
+ end
20
+
21
+ def save_under_funded_projects(to_file)
22
+ File.open(to_file, "w") do |file|
23
+ file.puts "Under funded projecs:"
24
+ under_funded_projects.each do |project|
25
+ file.puts print_project_stats(project)
26
+ # file << print_project_stats(project)
27
+ end
28
+ end
29
+ end
30
+
31
+ def add_project(project)
32
+ @projects << project
33
+ end
34
+
35
+ def request_funding(rounds)
36
+ pledges = PledgePool::PLEDGES
37
+ puts "There are #{pledges.size} pledges:"
38
+ pledges.each do |pledge|
39
+ puts "\tA #{pledge.name} plage is worth #{pledge.amount}"
40
+ end
41
+
42
+ 1.upto(rounds) do |round|
43
+ puts "\nRequest Funding on Round: #{round}"
44
+ @projects.each do |project|
45
+ FundingRound.take_turn(project)
46
+ end
47
+ end
48
+ end
49
+
50
+ def print_project_stats(project)
51
+ "#{project.name}".ljust(30, '.') + "#{project.funding}".ljust(9,'.') + "#{project.target_funding}"
52
+ end
53
+
54
+ def print_project_funding_left(project)
55
+ "#{project.name}".ljust(30, '.') + "#{project.funding_left}"
56
+ end
57
+
58
+ def under_funded_projects
59
+ under_funded = @projects.reject { |project| project.fully_funded? }
60
+ end
61
+
62
+ def fully_funded_projects
63
+ @projects.select { |project| project.fully_funded? }
64
+ end
65
+
66
+ def print_stats
67
+ puts "\nStats for #{@name}"
68
+ # fully_funded, under_funded = @projects.partition { |project| project.fully_funded? }
69
+
70
+ fully_funded = fully_funded_projects
71
+ under_funded = under_funded_projects
72
+
73
+ puts "\nFully funded projecs:"
74
+ fully_funded.each { |project| puts print_project_stats(project) }
75
+
76
+ puts "\nUnder funded projecs:"
77
+ under_funded.each { |project| puts print_project_stats(project) }
78
+
79
+ puts "\nProjects with more fundings left"
80
+ under_funded.sort.each { |project| puts print_project_funding_left(project) }
81
+
82
+ @projects.each do |project|
83
+ puts "\nProject #{project.name} pledges:"
84
+ project.each_pledge do |pledge|
85
+ puts "$#{pledge.amount} in #{pledge.name} pledges"
86
+ end
87
+ puts "$#{project.pledges_amount} in total pledges"
88
+ end
89
+
90
+ # @projects.sort.each { |project| puts print_project_funding_left(project) unless project.fully_funded? }
91
+ end
92
+
93
+ # def print_project_stats(project)
94
+ # puts "#{project.name}".ljust(30,'.') + "#{project.funding_left}"
95
+ # end
96
+
97
+ def total_pledges_amount
98
+ @projects.each.reduce(0) { |sum, project| sum += project.pledges_amount }
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'project'
2
+
3
+ module FundraisingProgram
4
+ class GrantProject < Project
5
+
6
+ def remove_fund
7
+ puts "The project #{@name} is a Grant project and can't have funds removed"
8
+ end
9
+ end
10
+ end
11
+
12
+ if __FILE__ == $0
13
+ grant = GrantProject.new("grant",400,1000)
14
+ puts grant
15
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'project'
2
+
3
+ module FundraisingProgram
4
+ class HalfWayProject < Project
5
+
6
+ def initialize(name, funding, target_funding, extra_funding=500)
7
+ super(name,funding,target_funding)
8
+ @extra_funding = extra_funding
9
+ end
10
+
11
+ def half_way_reached?(funding1, funding2)
12
+ (funding1 < target_funding / 2) && (funding2 >= target_funding/2)
13
+ end
14
+
15
+ def add_fund
16
+ funding1 = total_funds
17
+ super
18
+ funding2 = total_funds
19
+ if half_way_reached?(funding1, funding2)
20
+ @funding += @extra_funding
21
+ end
22
+ end
23
+
24
+ def add_pledge(pledge)
25
+ funding1 = total_funds
26
+ super(pledge)
27
+ funding2 = total_funds
28
+ if half_way_reached?(funding1, funding2)
29
+ @funding += @extra_funding
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module FundraisingProgram
2
+ Pledge = Struct.new(:name, :amount)
3
+
4
+ module PledgePool
5
+ PLEDGES = [
6
+ Pledge.new(:bronze, 50),
7
+ Pledge.new(:silver, 75),
8
+ Pledge.new(:gold, 100),
9
+ ]
10
+
11
+ def self.random
12
+ PLEDGES.sample
13
+ end
14
+ end
15
+ end
16
+
17
+ if __FILE__ == $0
18
+ # puts TreasureTrove::TREASURES
19
+
20
+ end
@@ -0,0 +1,59 @@
1
+ require_relative 'pledge_pool'
2
+ require_relative 'fundable'
3
+
4
+ module FundraisingProgram
5
+ class Project
6
+ include Fundable
7
+
8
+ attr_reader :target_funding, :pledges_accumulated
9
+ attr_accessor :name, :funding
10
+
11
+ def initialize( name, funding = 0, target_funding = 1000 )
12
+ @name = name.capitalize
13
+ @funding = funding
14
+ @target_funding = target_funding
15
+ @pledges_accumulated = Hash.new(0)
16
+ end
17
+
18
+ def self.from_csv(line)
19
+ name, funding, target_funding = line.split(',')
20
+ Project.new(name, Integer(funding), Integer(target_funding))
21
+ end
22
+
23
+ def each_pledge
24
+ @pledges_accumulated.each do |name, amount|
25
+ pledge = Pledge.new(name,amount)
26
+ yield pledge
27
+ end
28
+ end
29
+
30
+ def to_s
31
+ "O projeto #{@name.upcase} tem investimento acumulado de R$ #{@funding} de R$ #{@target_funding} desejados. Faltam R$ #{funding_left} para o objetivo ser alcancado!"
32
+ end
33
+
34
+ def funding_left
35
+ target_funding - total_funds
36
+ end
37
+
38
+ def name=(new_name)
39
+ @name = new_name.capitalize
40
+ end
41
+
42
+ def <=>(other)
43
+ other.funding_left <=> funding_left
44
+ end
45
+
46
+ def add_pledge(pledge)
47
+ @pledges_accumulated[pledge.name] += pledge.amount
48
+ end
49
+
50
+ def total_funds
51
+ @funding + pledges_amount
52
+ end
53
+
54
+ def pledges_amount
55
+ @pledges_accumulated.values.reduce(0, :+)
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ require 'stringio'
2
+ require 'fundraising_program/fundrequest'
3
+ require 'fundraising_program/pledge_pool'
4
+
5
+ module FundraisingProgram
6
+ describe FundRequest do
7
+ $stdout = StringIO.new
8
+
9
+ context "Program with only one project" do
10
+ before do
11
+ @initial_funding = 100
12
+ @target_funding = 230
13
+ @project = Project.new('ABC', @initial_funding, @target_funding)
14
+ @program = FundRequest.new('Start-ups raising program')
15
+ @program.add_project(@project)
16
+ end
17
+
18
+ it "increases funding amount when gets a new investiment (low number - roll_number = 1)" do
19
+ allow_any_instance_of(Die).to receive(:roll).and_return(1)
20
+ @program.request_funding(1)
21
+ expect(@project.funding).to eq(@initial_funding+25)
22
+ end
23
+
24
+ it "increases funding amount when gets a new investiment (low number - roll_number = 2)" do
25
+ allow_any_instance_of(Die).to receive(:roll).and_return(2)
26
+ @program.request_funding(1)
27
+ expect(@project.funding).to eq(@initial_funding+25)
28
+ end
29
+
30
+ it "decreases funding amount when loses an investiment (medium number - roll_number = 3)" do
31
+ allow_any_instance_of(Die).to receive(:roll).and_return(3)
32
+ @program.request_funding(1)
33
+ expect(@project.funding).to eq(@initial_funding)
34
+ end
35
+
36
+ it "keeps the funding amount when neither gets nor loses investiment (high number - roll_number = 4)" do
37
+ allow_any_instance_of(Die).to receive(:roll).and_return(4)
38
+ @program.request_funding(1)
39
+ expect(@project.funding).to eq(@initial_funding-15)
40
+ end
41
+
42
+ it "keeps the funding amount when neither gets nor loses investiment (high number - roll_number = 5)" do
43
+ allow_any_instance_of(Die).to receive(:roll).and_return(5)
44
+ @program.request_funding(1)
45
+ expect(@project.funding).to eq(@initial_funding-15)
46
+ end
47
+
48
+ it "computes total points as the sum of all player points" do
49
+ fund_program = FundRequest.new("VC-Friendly Start-up Projects")
50
+ project1 = Project.new( 'parkav', 669, 700 );
51
+ project2 = Project.new( 'plate iq', 654, 700 );
52
+ project3 = Project.new( 'bagaveev', 1128, 1600 );
53
+ project4 = Project.new( 'flaviar', 2912, 3400 );
54
+
55
+ fund_program.add_project(project1)
56
+ fund_program.add_project(project2)
57
+ fund_program.add_project(project3)
58
+ fund_program.add_project(project4)
59
+
60
+ project1.add_pledge(Pledge.new(:bronze, 50))
61
+ project2.add_pledge(Pledge.new(:bronze, 50))
62
+ project3.add_pledge(Pledge.new(:bronze, 50))
63
+ # game.total_points.should == 500
64
+ expect(fund_program.total_pledges_amount).to eq(150)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ require 'fundraising_program/grant_project'
2
+
3
+ module FundraisingProgram
4
+ describe GrantProject do
5
+ $stdout = StringIO.new
6
+
7
+ before do
8
+ @initial_funding = 200
9
+ @project = GrantProject.new("Grant", @initial_funding, 2030)
10
+ end
11
+
12
+ it "doesn't lose funds when there is a remove_fund" do
13
+ @project.remove_fund
14
+ expect(@project.funding).to eq(@initial_funding)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ require 'fundraising_program/half_way_project'
2
+
3
+ module FundraisingProgram
4
+ describe HalfWayProject do
5
+ $stdout = StringIO.new
6
+
7
+ context "Reaches half of the target_funding" do
8
+
9
+ before do
10
+ @initial_funding = 400
11
+ @target_funding = 1000
12
+ @extra_funding = 500
13
+ @project = HalfWayProject.new("half way", @initial_funding, @target_funding, @extra_funding)
14
+ end
15
+
16
+ it "recognizes when half targe funding is reached" do
17
+ funding1 = 400
18
+ funding2 = 500
19
+ expect(@project.half_way_reached?(funding1,funding2)).to eq(true)
20
+ end
21
+
22
+ it "doens't reach half of the target_funding" do
23
+ 1.upto(3) { @project.add_fund }
24
+ expect(@project.total_funds).to eq(@initial_funding + 3*25)
25
+
26
+ end
27
+
28
+ it "reaches half of the target_funding after add_fund" do
29
+ turns = 5
30
+ 1.upto(turns) { @project.add_fund }
31
+ expect(@project.total_funds).to eq(@initial_funding + turns*25 + @extra_funding)
32
+ end
33
+ end
34
+
35
+ context "doesn't reaches half of the target_funding" do
36
+
37
+ before do
38
+ @initial_funding = 100
39
+ @target_funding = 1000
40
+ @extra_funding = 500
41
+ @project = HalfWayProject.new("half way", @initial_funding, @target_funding, @extra_funding)
42
+ end
43
+
44
+ it "getting insufficient funds" do
45
+ turns = 4
46
+ 1.upto(turns) { @project.add_fund }
47
+ expect(@project.total_funds).to eq(@initial_funding + turns*25)
48
+ end
49
+
50
+ it "gettting insufficient pledges" do
51
+ turns = 3
52
+ 1.upto(turns) { @project.add_pledge(Pledge.new(:bronze,50)) }
53
+ expect(@project.total_funds).to eq(@initial_funding + turns*50)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,46 @@
1
+ require 'fundraising_program/pledge_pool'
2
+ # require_relative 'spec_helper'
3
+
4
+ module FundraisingProgram
5
+ describe Pledge do
6
+
7
+ before do
8
+ @pledge = Pledge.new(:bronze, 50)
9
+ end
10
+
11
+ it "has a name attribute" do
12
+ expect(@pledge.name).to eq(:bronze)
13
+ # @treasure.name.should == :hammer
14
+ end
15
+
16
+ it "has an amount attribute" do
17
+ # @treasure.points.should == 50
18
+ expect(@pledge.amount).to eq(50)
19
+ end
20
+
21
+ end
22
+
23
+ describe PledgePool do
24
+
25
+ it "has tree levels" do
26
+ expect(PledgePool::PLEDGES.size).to eq(3)
27
+ end
28
+
29
+ it "has a bronze level worth $50" do
30
+ expect(PledgePool::PLEDGES[0]).to eq(Pledge.new(:bronze, 50))
31
+ end
32
+
33
+ it "has a silver level worth $75" do
34
+ expect(PledgePool::PLEDGES[1]).to eq(Pledge.new(:silver, 75))
35
+ end
36
+
37
+ it "has a gold level worth $100" do
38
+ expect(PledgePool::PLEDGES[2]).to eq(Pledge.new(:gold, 100))
39
+ end
40
+
41
+ it "gets a valid pledge ramdomly" do
42
+ expect(PledgePool::PLEDGES.include?(PledgePool::random)).to eq(true)
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,161 @@
1
+ require 'fundraising_program/spec_helper'
2
+ require 'fundraising_program/project'
3
+ require 'fundraising_program/pledge_pool'
4
+
5
+ module FundraisingProgram
6
+ describe Project do
7
+
8
+ $stdout = StringIO.new # evita que puts seja impresso no terminal ao rodar rspec
9
+
10
+ before do
11
+ @initial_funding = 100
12
+ @target_funding = 200
13
+ @project = Project.new('ABC', @initial_funding, @target_funding)
14
+ end
15
+
16
+ it "has an initial target funding amount" do
17
+ expect(@project.target_funding).to eq(200)
18
+ end
19
+
20
+ it "computes the total funding outsdanding as the target funding amount minus the funding amount" do
21
+ expect(@project.funding_left).to eq(@project.target_funding - @project.funding)
22
+ end
23
+
24
+ it "increases funds by 25 when funds are added" do
25
+ @project.add_fund
26
+ expect(@project.funding).to eq(@initial_funding + 25)
27
+ end
28
+
29
+
30
+ it "decreases funds by 15 when funds are removed" do
31
+ @project.remove_fund
32
+ expect(@project.funding).to eq(@initial_funding - 15)
33
+ end
34
+
35
+ it "calculates left funding corectly" do
36
+ expect(@project.funding_left).to eq(@project.target_funding - @project.funding)
37
+ end
38
+
39
+ it "is fully funded" do
40
+ expect(@project).not_to be_fully_funded
41
+ end
42
+
43
+ it "has a pledge_accumulator" do
44
+ expect(@project.pledges_accumulated.class).to eq(Hash.new.class)
45
+ end
46
+
47
+ it "adds a new pledge" do
48
+ pledge = PledgePool.random
49
+ @project.add_pledge(pledge)
50
+ expect(@project.pledges_accumulated.keys.include?(pledge.name)).to eq(true)
51
+ end
52
+
53
+ it "yields each pledge and its total points" do
54
+ @project.add_pledge(Pledge.new(:bronze, 50))
55
+ @project.add_pledge(Pledge.new(:bronze, 50))
56
+ @project.add_pledge(Pledge.new(:silver, 75))
57
+ @project.add_pledge(Pledge.new(:silver, 75))
58
+ @project.add_pledge(Pledge.new(:silver, 75))
59
+ @project.add_pledge(Pledge.new(:gold, 100))
60
+ @project.add_pledge(Pledge.new(:gold, 100))
61
+ yielded = []
62
+
63
+ @project.each_pledge do |pledge|
64
+ yielded << pledge
65
+ end
66
+ # yielded.should == [
67
+ # Treasure.new(:skillet, 200),
68
+ # Treasure.new(:hammer, 50),
69
+ # Treasure.new(:bottle, 25)
70
+ # ]
71
+
72
+ expect(yielded).to eq( [
73
+ Pledge.new(:bronze, 100),
74
+ Pledge.new(:silver, 225),
75
+ Pledge.new(:gold, 200)
76
+ ])
77
+ end
78
+
79
+ it "creates a project from a csv line" do
80
+ line = "Project1,100,0"
81
+ expect(puts Project.from_csv(line)).to eq(puts Project.new("Project1",100,0))
82
+ end
83
+
84
+ context "which got a bronze and a silver pledge" do
85
+
86
+ before do
87
+ @initial_funding = 100
88
+ @target_funding = 200
89
+ @project = Project.new('ABC', @initial_funding, @target_funding)
90
+ @project.add_pledge(PledgePool::PLEDGES[0])
91
+ @project.add_pledge(PledgePool::PLEDGES[1])
92
+ end
93
+
94
+ it "has $125 in pladges" do
95
+ expect(@project.pledges_amount).to eq(PledgePool::PLEDGES[0].amount + PledgePool::PLEDGES[1].amount)
96
+ end
97
+ end
98
+
99
+ context "with initial fund of 100, got a bronze pledge and received $100 in funds" do
100
+
101
+ before do
102
+ @initial_funding = 100
103
+ @target_funding = 200
104
+ @project = Project.new('ABC', @initial_funding, @target_funding)
105
+ @project.add_pledge(PledgePool::PLEDGES[0]) # adds a bronze pledge ($50)
106
+ @project.add_fund
107
+ end
108
+
109
+ it "has $175 as total funds" do
110
+ expect(@project.total_funds).to eq(175)
111
+ end
112
+ end
113
+
114
+
115
+
116
+ context "created with default value for amount funding amount and target funding amount" do
117
+
118
+ before do
119
+ @project = Project.new('ABC')
120
+ end
121
+
122
+ it "has a default value of 0 for funding amount" do
123
+ expect(@project.funding).to eq(0)
124
+ end
125
+
126
+ it "has a default value of 1000 for target funding amount" do
127
+ expect(@project.target_funding).to eq(1000)
128
+ end
129
+ end
130
+
131
+
132
+ context "fully funded project" do
133
+
134
+ before do
135
+ @initial_funding = 100
136
+ @target_funding = 200
137
+ @project = Project.new('ABC', @initial_funding, @target_funding)
138
+ end
139
+
140
+
141
+ it "is fully funded" do
142
+ expect(@project).not_to be_fully_funded
143
+ end
144
+ end
145
+
146
+ context "in a collection of projects" do
147
+ before do
148
+ project1 = Project.new( 'parkav', 1000, 100 );
149
+ project2 = Project.new( 'plate iq', 1500, 100 );
150
+ project3 = Project.new( 'bagaveev', 2000, 100 );
151
+ project4 = Project.new( 'flaviar', 3000, 100 );
152
+ @projects = [@project1, @project2, @project3, @project4]
153
+ end
154
+ it "is sorted by decreasing funding_left" do
155
+ @projects.sort.should == [@project4, @project3, @project2, @project3]
156
+ end
157
+ end
158
+
159
+
160
+ end
161
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = [:should, :expect]
4
+ end
5
+ config.mock_with :rspec do |c|
6
+ c.syntax = [:should, :expect]
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mfp_fundraising_program
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Parreiras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 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.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: This is the project developed following the Pragmatic Studio for Ruby
28
+ and following the bonus rounds from across exercises.
29
+ email: marcosfparreiras@gmail.com
30
+ executables:
31
+ - fundraising_program
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README
37
+ - bin/fundraising_program
38
+ - bin/projects.csv
39
+ - bin/under_fundeds_projects.txt
40
+ - lib/fundraising_program/die.rb
41
+ - lib/fundraising_program/fundable.rb
42
+ - lib/fundraising_program/funding_round.rb
43
+ - lib/fundraising_program/fundrequest.rb
44
+ - lib/fundraising_program/grant_project.rb
45
+ - lib/fundraising_program/half_way_project.rb
46
+ - lib/fundraising_program/pledge_pool.rb
47
+ - lib/fundraising_program/project.rb
48
+ - spec/fundraising_program/fundrequest_spec.rb
49
+ - spec/fundraising_program/grant_project_spec.rb
50
+ - spec/fundraising_program/half_way_project_spec.rb
51
+ - spec/fundraising_program/pledge_pool_spec.rb
52
+ - spec/fundraising_program/project_spec.rb
53
+ - spec/fundraising_program/spec_helper.rb
54
+ homepage: ''
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
+ rubyforge_project:
74
+ rubygems_version: 2.4.5
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: fundraising application as a learning ruby program
78
+ test_files:
79
+ - spec/fundraising_program/fundrequest_spec.rb
80
+ - spec/fundraising_program/pledge_pool_spec.rb
81
+ - spec/fundraising_program/grant_project_spec.rb
82
+ - spec/fundraising_program/half_way_project_spec.rb
83
+ - spec/fundraising_program/spec_helper.rb
84
+ - spec/fundraising_program/project_spec.rb