Module: CaTissue::Person

Includes:
CaRuby::Person
Included in:
Participant, User
Defined in:
lib/catissue/helpers/person.rb

Overview

Mix-in for domain classes that define the first_name, last_name and optional middle_name attributes.

Instance Method Summary collapse

Instance Method Details

#nameObject

Returns this Person’s name as a Name structure, or nil if there is no last name.



11
12
13
14
# File 'lib/catissue/helpers/person.rb', line 11

def name
  middle = middle_name if respond_to?(:middle_name)
  Name.new(last_name, first_name, middle) if last_name
end

#name=(value) ⇒ Object

Sets this Person’s name to the name string or Name object. A string name argument is parsed using Name.parse.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/catissue/helpers/person.rb', line 20

def name=(value)
  value = Name.parse(value) if String === value
  # a missing name is equivalent to an empty name for our purposes here
  value = Name.new(nil, nil) if value.nil?
  unless Name === value then
    raise ArgumentError.new("Name argument type invalid; expected <#{Name}>, found <#{value.class}>")
  end
  self.first_name = value.first
  self.last_name = value.last
  self.middle_name = value.middle if respond_to?(:middle_name)
end