Module: Juscribe::Personhood

Extended by:
ActiveSupport::Concern
Defined in:
lib/juscribe/personhood.rb

Instance Method Summary collapse

Instance Method Details

#ageObject



57
58
59
60
61
62
# 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?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/juscribe/personhood.rb', line 81

def androgynous?
  read_attribute(:sex).nil?
end

#birthdateObject

Defaults to Date.today if nil.



53
54
55
# File 'lib/juscribe/personhood.rb', line 53

def birthdate
  read_attribute(:birthdate) || Date.today
end

#email_addressObject

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



48
49
50
# File 'lib/juscribe/personhood.rb', line 48

def email_address
  "#{first_and_last_name} <#{email}>" if email.present?
end

#female?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/juscribe/personhood.rb', line 77

def female?
  sex == 'f'
end

#first_and_last_nameObject

Same as #full_name but omitting the middle_name.



42
43
44
# File 'lib/juscribe/personhood.rb', line 42

def first_and_last_name
  display_optional name.first_and_last
end

#full_nameObject

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



37
38
39
# File 'lib/juscribe/personhood.rb', line 37

def full_name
  display_optional name.full
end

#male?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/juscribe/personhood.rb', line 73

def male?
  sex == 'm'
end

#middle_initialObject



31
32
33
# File 'lib/juscribe/personhood.rb', line 31

def middle_initial
  display_optional name.middle_initial
end

#sex(format = nil) ⇒ Object



64
65
66
67
68
69
70
71
# 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_paramObject

Override the following to control what gets displayed on #to_s



27
28
29
# File 'lib/juscribe/personhood.rb', line 27

def to_param
  username
end