Class: Pr::Project
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fundable
#fully_funded?, #got, #lost, #total_funding_outstanding
Constructor Details
#initialize(name, funding_a = 0, funding_t = 300) ⇒ Project
Returns a new instance of Project.
9
10
11
12
13
14
|
# File 'lib/project.rb', line 9
def initialize(name,funding_a=0,funding_t=300)
@name = name.capitalize
@amount = funding_a
@target = funding_t
@received_pledge = Hash.new(0)
end
|
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
6
7
8
|
# File 'lib/project.rb', line 6
def amount
@amount
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/project.rb', line 7
def name
@name
end
|
#target ⇒ Object
Returns the value of attribute target.
6
7
8
|
# File 'lib/project.rb', line 6
def target
@target
end
|
Class Method Details
.from_csv(line) ⇒ Object
15
16
17
18
|
# File 'lib/project.rb', line 15
def self.from_csv(line)
name, amount,target = line.split(',')
project = Project.new(name, Integer(amount), Integer(target))
end
|
Instance Method Details
#<=>(other) ⇒ Object
23
24
25
|
# File 'lib/project.rb', line 23
def <=>(other)
other.amount <=> @amount
end
|
#each_received_pledge ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/project.rb', line 46
def each_received_pledge
@received_pledge.each do |name, funds|
pledge = Prize.new(name, funds)
yield pledge
end
end
|
#pledges ⇒ Object
38
39
40
|
# File 'lib/project.rb', line 38
def pledges
@received_pledge.values.reduce(0, :+)
end
|
#received_pledge(pledge) ⇒ Object
32
33
34
35
36
|
# File 'lib/project.rb', line 32
def received_pledge(pledge)
@received_pledge[pledge.name] += pledge.amount
puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.amount}."
puts "#{@name}'s pledges: #{@received_pledge}"
end
|
#time ⇒ Object
19
20
21
22
|
# File 'lib/project.rb', line 19
def time
current_time = Time.new
current_time.strftime("%A, %B %d, %Y")
end
|
#to_s ⇒ Object
26
27
28
29
30
|
# File 'lib/project.rb', line 26
def to_s
"Project #{@name} has #{total_funds}$ in funding as of #{time} , towards a goal of $#{@target}
Total funding still needed is : $#{total_funding_outstanding}
------------------------"
end
|
#total_funds ⇒ Object
42
43
44
|
# File 'lib/project.rb', line 42
def total_funds
@amount + pledges
end
|