Class: CrowdFund::Project

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

Direct Known Subclasses

GrantProject

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fundable

#<=>, #funded?

Constructor Details

#initialize(name, fund, goal) ⇒ Project

Returns a new instance of Project.



6
7
8
9
10
# File 'lib/crowdfund/funds.rb', line 6

def initialize(name, fund, goal)
    @name = name
    @fund = fund
    @goal = goal
end

Instance Attribute Details

#fundObject

Returns the value of attribute fund.



4
5
6
# File 'lib/crowdfund/funds.rb', line 4

def fund
  @fund
end

#goalObject (readonly)

Returns the value of attribute goal.



4
5
6
# File 'lib/crowdfund/funds.rb', line 4

def goal
  @goal
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/crowdfund/funds.rb', line 3

def name
  @name
end

Instance Method Details

#each_earned_pledgeObject



26
27
28
29
30
# File 'lib/crowdfund/project.rb', line 26

def each_earned_pledge
    @earned_pledges.each do |name, amount|
    yield Pledge.new(name, amount)
    end
end

#earn_pledge(pledge) ⇒ Object



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

def earn_pledge(pledge)
    @earned_pledges[pledge.name] += pledge.amount
    @fund += pledge.amount
    puts "#{@name} earned a #{pledge.name} pledge worth $#{pledge.amount}"
    puts "#{@name}'s pledges: #{@earned_pledges}"
end

#gainedObject



12
13
14
15
# File 'lib/crowdfund/funds.rb', line 12

def gained
    @fund += 25
    puts "Project #{@name} got more funds!"
end

#lostObject



17
18
19
20
# File 'lib/crowdfund/funds.rb', line 17

def lost
    @fund -= 15
    puts "Project #{@name} lost some funds!"
end

#needObject



22
23
24
# File 'lib/crowdfund/funds.rb', line 22

def need
    @goal - @fund
end

#rewardsObject



32
33
34
# File 'lib/crowdfund/project.rb', line 32

def rewards 
    @earned_pledges.values.reduce(0, :+)
end

#to_sObject

Moved to fundable

def gained
  @fund += 25
  puts "Project #{@name} got more funds!"
end 
def lost
  @fund -= 15
  puts "Project #{@name} lost some funds!"
end
def need
  @goal - @fund
end
def funded?
  @fund >= @goal
end
def <=>(other_project)
  other_project.need <=> need
end


55
56
57
# File 'lib/crowdfund/project.rb', line 55

def to_s
    "Project #{@name} has $#{@fund} in fundinfg towards a goal of $#{@goal} => still need $#{need}"
end