Class: CrowdFund::Project
- Inherits:
-
Object
- Object
- CrowdFund::Project
- Defined in:
- lib/crowd_fund/project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#name ⇒ Object
Returns the value of attribute name.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #each_pledge_received ⇒ Object
-
#initialize(name, amount = 0, target = 1000) ⇒ Project
constructor
A new instance of Project.
- #receive_pledge(pledge) ⇒ Object
- #total_pledges ⇒ Object
Methods included from Printable
Methods included from Fundable
#<=>, #add, #full?, #remove, #stats, #total_to_fund
Constructor Details
#initialize(name, amount = 0, target = 1000) ⇒ Project
Returns a new instance of Project.
13 14 15 16 17 18 |
# File 'lib/crowd_fund/project.rb', line 13 def initialize(name, amount=0, target=1000) @name = name.upcase @amount = amount @target = target @pledges_received = Hash.new(0) end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
11 12 13 |
# File 'lib/crowd_fund/project.rb', line 11 def amount @amount end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/crowd_fund/project.rb', line 11 def name @name end |
#target ⇒ Object
Returns the value of attribute target.
11 12 13 |
# File 'lib/crowd_fund/project.rb', line 11 def target @target end |
Instance Method Details
#each_pledge_received ⇒ Object
24 25 26 27 28 |
# File 'lib/crowd_fund/project.rb', line 24 def each_pledge_received @pledges_received.each do |name, value| yield Pledge.new(name, value) end end |
#receive_pledge(pledge) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/crowd_fund/project.rb', line 30 def receive_pledge(pledge) @pledges_received[pledge.name] += pledge.value @amount += total_pledges puts "#{@name} received a #{pledge.name} pledge worth $#{pledge.value}." puts "Project #{@name} pledges: #{@pledges_received}" end |
#total_pledges ⇒ Object
20 21 22 |
# File 'lib/crowd_fund/project.rb', line 20 def total_pledges @pledges_received.values.reduce(0, :+) end |