Class: CrowdFund::Project
- Inherits:
-
Object
- Object
- CrowdFund::Project
show all
- Includes:
- Fundable
- Defined in:
- lib/crowd_fund/project.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fundable
#add_funds, #add_to_funds, #fully_funded?, #remove_from_funds, #remove_funds
Constructor Details
#initialize(name, initial_funding_amount, target_funding_amount = 0) ⇒ Project
Returns a new instance of Project.
12
13
14
15
16
17
|
# File 'lib/crowd_fund/project.rb', line 12
def initialize(name, initial_funding_amount, target_funding_amount = 0)
@name = name
@current_funding_amount = @initial_funding_amount = initial_funding_amount
@target_funding_amount = target_funding_amount
@received_pledges = Hash.new(0)
end
|
Instance Attribute Details
#current_funding_amount ⇒ Object
Returns the value of attribute current_funding_amount.
9
10
11
|
# File 'lib/crowd_fund/project.rb', line 9
def current_funding_amount
@current_funding_amount
end
|
#initial_funding_amount ⇒ Object
Returns the value of attribute initial_funding_amount.
10
11
12
|
# File 'lib/crowd_fund/project.rb', line 10
def initial_funding_amount
@initial_funding_amount
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/crowd_fund/project.rb', line 9
def name
@name
end
|
#target_funding_amount ⇒ Object
Returns the value of attribute target_funding_amount.
10
11
12
|
# File 'lib/crowd_fund/project.rb', line 10
def target_funding_amount
@target_funding_amount
end
|
Class Method Details
.from_csv(string) ⇒ Object
52
53
54
55
|
# File 'lib/crowd_fund/project.rb', line 52
def self.from_csv(string)
name, initial_funding_amount = string.split(',')
Project.new(name, Integer(initial_funding_amount))
end
|
Instance Method Details
#each_received_pledge ⇒ Object
41
42
43
44
45
|
# File 'lib/crowd_fund/project.rb', line 41
def each_received_pledge
@received_pledges.each do |name, amount|
yield Pledge.new(name, amount)
end
end
|
#funding_needed_entry ⇒ Object
47
48
49
50
|
# File 'lib/crowd_fund/project.rb', line 47
def funding_needed_entry
formatted_name = @name.ljust(20, '.')
"#{formatted_name} #{total_funding_still_needed}"
end
|
#pledges ⇒ Object
33
34
35
|
# File 'lib/crowd_fund/project.rb', line 33
def pledges
@received_pledges.values.reduce(0, :+)
end
|
#received_pledge(pledge) ⇒ Object
27
28
29
30
31
|
# File 'lib/crowd_fund/project.rb', line 27
def received_pledge(pledge)
@received_pledges[pledge.name] += pledge.amount
puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.amount}."
puts "#{@name}'s pledges: #{@received_pledges}"
end
|
#to_s ⇒ Object
19
20
21
|
# File 'lib/crowd_fund/project.rb', line 19
def to_s
"Project #{@name} has $#{total_funding_received} towards a goal of $#{@target_funding_amount}."
end
|
#total_funding_received ⇒ Object
37
38
39
|
# File 'lib/crowd_fund/project.rb', line 37
def total_funding_received
@current_funding_amount + pledges
end
|
#total_funding_still_needed ⇒ Object
23
24
25
|
# File 'lib/crowd_fund/project.rb', line 23
def total_funding_still_needed
@target_funding_amount - total_funding_received
end
|