Module: KirguduBase::Models::Methods::PersonAge

Defined in:
app/helpers/kirgudu_base/models/methods.rb

Instance Method Summary collapse

Instance Method Details

#ageObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/kirgudu_base/models/methods.rb', line 6

def age
  bd = nil
  the_age = nil
  if self.respond_to?(:birth_date) && (self.birth_date.is_a?(Date) || self.birth_date.is_a?(DateTime))
    bd = self.birth_date
  elsif self.respond_to?(:birthdate) && (self.birthdate.is_a?(Date) || self.birthdate.is_a?(DateTime))
    bd = self.birthdate
  end
  if bd
    the_age = Date.today.year - bd.year
    the_age -= 1 if Date.today < bd + the_age.years #for days before birthday
  end
  the_age
end

#days_to_next_birth_dateObject



35
36
37
# File 'app/helpers/kirgudu_base/models/methods.rb', line 35

def days_to_next_birth_date
  (next_birth_date - Date.today).to_s
end

#next_birth_dateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/kirgudu_base/models/methods.rb', line 21

def next_birth_date
  bd = nil
  next_bd = nil
  if self.respond_to?(birth_date) && (self.birth_date.is_a?(Date) || self.birth_date.is_a?(DateTime))
    bd = self.birth_date
  elsif self.respond_to?(birthdate) && (self.birthdate.is_a?(Date) || self.birthdate.is_a?(DateTime))
    bd = self.birthdate
  end
  if bd
    next_bd = birth_date + (age+1).years
  end
  next_bd
end