Module: Petli::Pet::Death

Extended by:
Tatty::DB::Attributes
Included in:
Petli::Pet
Defined in:
lib/petli/pet/death.rb

Instance Method Summary collapse

Methods included from Tatty::DB::Attributes

db_attr

Instance Method Details

#check_if_deadObject



8
9
10
# File 'lib/petli/pet/death.rb', line 8

def check_if_dead
  die! if unhappy? && unhealthy? && (too_sick? || too_hungry?)
end

#dead?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/petli/pet/death.rb', line 36

def dead?
  !self.died_at.nil?
end

#die!Object



12
13
14
# File 'lib/petli/pet/death.rb', line 12

def die!
  self.died_at = Time.now
end

#lifetimeObject



40
41
42
# File 'lib/petli/pet/death.rb', line 40

def lifetime
  (self.died_at.nil? ? days_since(self.birth) : days_since(self.birth, self.died_at)).to_i
end

#sick?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/petli/pet/death.rb', line 16

def sick?
  self.sick > 0
end

#too_hungry?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/petli/pet/death.rb', line 24

def too_hungry?
  days_since(self.last_meal) >= 1
end

#too_sick?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/petli/pet/death.rb', line 20

def too_sick?
  self.sick > 2
end

#unhappy?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/petli/pet/death.rb', line 28

def unhappy?
  self.happiness <= 1
end

#unhealthy?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/petli/pet/death.rb', line 32

def unhealthy?
  self.health <= 1
end