Class: CrowdFund::GrantProject

Inherits:
Project
  • Object
show all
Defined in:
lib/crowdfund/grant_project.rb

Instance Attribute Summary

Attributes inherited from Project

#fund, #goal, #name

Instance Method Summary collapse

Methods inherited from Project

#each_earned_pledge, #gained, #need, #rewards, #to_s

Methods included from Fundable

#<=>, #funded?, #gained, #need

Constructor Details

#initialize(name, fund, goal, charity_ratio = 0.5) ⇒ GrantProject

Returns a new instance of GrantProject.



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

def initialize(name, fund, goal, charity_ratio=0.5)
    super(name, fund, goal)
    @charity_ratio = charity_ratio
end

Instance Method Details

#earn_pledge(pledge) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/crowdfund/grant_project.rb', line 20

def earn_pledge(pledge)
    if secured?
    puts "#{@name} is secured and gives #{@charity_ratio} of #{pledge.name} to charity."
    shared_amount = pledge.amount * @charity_ratio
    pledge = Pledge.new(pledge.name, shared_amount)
    end
    super(pledge)
end

#lostObject



16
17
18
# File 'lib/crowdfund/grant_project.rb', line 16

def lost
    puts "#{@name} is a Grant Poject : funds cannot be removed!"
end

#secured?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/crowdfund/grant_project.rb', line 11

def secured?
    #  project is secured when it has accumulated more thant half of its goal
    @fund > (goal / 2)
end