Class: FundraisingProgram::Project
- Inherits:
-
Object
- Object
- FundraisingProgram::Project
show all
- Includes:
- Fundable
- Defined in:
- lib/fundraising_program/project.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fundable
#add_fund, #fully_funded?, #remove_fund
Constructor Details
#initialize(name, funding = 0, target_funding = 1000) ⇒ Project
Returns a new instance of Project.
11
12
13
14
15
16
|
# File 'lib/fundraising_program/project.rb', line 11
def initialize( name, funding = 0, target_funding = 1000 )
@name = name.capitalize
@funding = funding
@target_funding = target_funding
@pledges_accumulated = Hash.new(0)
end
|
Instance Attribute Details
#funding ⇒ Object
Returns the value of attribute funding.
9
10
11
|
# File 'lib/fundraising_program/project.rb', line 9
def funding
@funding
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/fundraising_program/project.rb', line 9
def name
@name
end
|
#pledges_accumulated ⇒ Object
Returns the value of attribute pledges_accumulated.
8
9
10
|
# File 'lib/fundraising_program/project.rb', line 8
def pledges_accumulated
@pledges_accumulated
end
|
#target_funding ⇒ Object
Returns the value of attribute target_funding.
8
9
10
|
# File 'lib/fundraising_program/project.rb', line 8
def target_funding
@target_funding
end
|
Class Method Details
.from_csv(line) ⇒ Object
18
19
20
21
|
# File 'lib/fundraising_program/project.rb', line 18
def self.from_csv(line)
name, funding, target_funding = line.split(',')
Project.new(name, Integer(funding), Integer(target_funding))
end
|
Instance Method Details
#<=>(other) ⇒ Object
42
43
44
|
# File 'lib/fundraising_program/project.rb', line 42
def <=>(other)
other.funding_left <=> funding_left
end
|
#add_pledge(pledge) ⇒ Object
46
47
48
|
# File 'lib/fundraising_program/project.rb', line 46
def add_pledge(pledge)
@pledges_accumulated[pledge.name] += pledge.amount
end
|
#each_pledge ⇒ Object
23
24
25
26
27
28
|
# File 'lib/fundraising_program/project.rb', line 23
def each_pledge
@pledges_accumulated.each do |name, amount|
pledge = Pledge.new(name,amount)
yield pledge
end
end
|
#funding_left ⇒ Object
34
35
36
|
# File 'lib/fundraising_program/project.rb', line 34
def funding_left
target_funding - total_funds
end
|
#pledges_amount ⇒ Object
54
55
56
|
# File 'lib/fundraising_program/project.rb', line 54
def pledges_amount
@pledges_accumulated.values.reduce(0, :+)
end
|
#to_s ⇒ Object
30
31
32
|
# File 'lib/fundraising_program/project.rb', line 30
def to_s
"O projeto #{@name.upcase} tem investimento acumulado de R$ #{@funding} de R$ #{@target_funding} desejados. Faltam R$ #{funding_left} para o objetivo ser alcancado!"
end
|
#total_funds ⇒ Object
50
51
52
|
# File 'lib/fundraising_program/project.rb', line 50
def total_funds
@funding + pledges_amount
end
|