Class: CrowdFund::Project

Inherits:
Object
  • Object
show all
Includes:
Fundable, Pledgeable
Defined in:
lib/crowdfund/project.rb

Direct Known Subclasses

GrantProject, SponsoredProject

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pledgeable

#each_pledge, #make_pledge, #pledged_funds, #total_funds

Methods included from Fundable

#<=>, #add_funds, #fully_funded?, #remove_funds

Constructor Details

#initialize(name, target, funding = 0) ⇒ Project

Returns a new instance of Project.



12
13
14
15
16
17
# File 'lib/crowdfund/project.rb', line 12

def initialize(name, target, funding=0)
  @name = name
  @funding = funding
  @target = target
  @pledges = Hash.new(0)
end

Instance Attribute Details

#fundingObject

Returns the value of attribute funding.



10
11
12
# File 'lib/crowdfund/project.rb', line 10

def funding
  @funding
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/crowdfund/project.rb', line 10

def name
  @name
end

#pledgesObject

Returns the value of attribute pledges.



10
11
12
# File 'lib/crowdfund/project.rb', line 10

def pledges
  @pledges
end

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/crowdfund/project.rb', line 10

def target
  @target
end

Instance Method Details

#outstanding_fundingObject



19
20
21
22
23
24
25
# File 'lib/crowdfund/project.rb', line 19

def outstanding_funding
  if fully_funded?
    0
  else
    @target - total_funds
  end
end

#statusObject



27
28
29
30
31
32
33
34
# File 'lib/crowdfund/project.rb', line 27

def status
  status = "\n#{@name} funded including pledges at $#{total_funds} for $#{@target} target"
  status += "\nProject #{@name}'s pledges:"
  each_pledge do |pledge|
    status += "\n$#{pledge.amount} in #{pledge.name} pledges"
  end
  status += "\n$#{pledged_funds} in total pledges"
end

#to_sObject



36
37
38
# File 'lib/crowdfund/project.rb', line 36

def to_s
  "Project #{@name} has $#{@funding} in funding towards a goal of $#{@target}"
end