module Juscribe::Personhood

Basic Info

↑ top

Public Instance Methods

age() click to toggle source
# File lib/juscribe/personhood.rb, line 57
def age
  today, bday = Date.today, birthdate
  years       = today.year - bday.year
  years.tap { |yrs| yrs -= 1 if (bday + years.years) > today }
  # is this logic even solid?
end
androgynous?() click to toggle source
# File lib/juscribe/personhood.rb, line 81
def androgynous?
  read_attribute(:sex).nil?
end
birthdate() click to toggle source

Defaults to Date.today if nil.

# File lib/juscribe/personhood.rb, line 53
def birthdate
  read_attribute(:birthdate) || Date.today
end
email_address() click to toggle source

Email, when the db field is nil, still returns an empty string, I suppose for Devise’s sake.

# File lib/juscribe/personhood.rb, line 48
def email_address
  "#{first_and_last_name} <#{email}>" if email.present?
end
female?() click to toggle source
# File lib/juscribe/personhood.rb, line 77
def female?
  sex == 'f'
end
first_and_last_name() click to toggle source

Same as full_name but omitting the middle_name.

# File lib/juscribe/personhood.rb, line 42
def first_and_last_name
  display_optional name.first_and_last
end
full_name() click to toggle source

Full name, unless empty, then shows “unnamed” variant.

# File lib/juscribe/personhood.rb, line 37
def full_name
  display_optional name.full
end
male?() click to toggle source
# File lib/juscribe/personhood.rb, line 73
def male?
  sex == 'm'
end
middle_initial() click to toggle source
# File lib/juscribe/personhood.rb, line 31
def middle_initial
  display_optional name.middle_initial
end
sex(format = nil) click to toggle source
# File lib/juscribe/personhood.rb, line 64
def sex(format = nil)
  full_int = format == :full ? 1 : 0
  if read_attribute(:sex)
    %w(female male)[self[:sex]][0..full_int.send(:-@)]
  else
    %w{? (unknown)}[full_int]
  end
end
to_param() click to toggle source

Override the following to control what gets displayed on to_s

# File lib/juscribe/personhood.rb, line 27
def to_param
  username
end

Private Instance Methods

strip_names!() click to toggle source
# File lib/juscribe/personhood.rb, line 86
def strip_names!
  %w(first_name middle_name last_name).each do |name_part|
    send(name_part).strip! if send(:"#{name_part}_changed?")
  end
end