Module: StudySubjectPii
- Included in:
- StudySubject
- Defined in:
- app/models/study_subject_pii.rb
Overview
Simply extracted some code to clean up model. I’d like to do this to all of the really big classes but let’s see how this goes first.
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/study_subject_pii.rb', line 7 def self.included(base) # Must delay the calls to these ActiveRecord methods # or it will raise many "undefined method"s. base.class_eval do # TODO include maiden_name just in case is mother??? def childs_names [first_name, middle_name, last_name ] end # Returns string containing study_subject's first, middle and last initials def initials childs_names.delete_if(&:blank?).collect{|s|s.chars.first}.join() end # Returns string containing study_subject's first, middle and last name # Use delete_if(&:blank?) instead of compact, which only removes nils. def full_name fullname = childs_names.delete_if(&:blank?).join(' ') ( fullname.blank? ) ? '[name not available]' : fullname end def fathers_names [father_first_name, father_middle_name, father_last_name ] end # Returns string containing study_subject's father's first, middle and last name def fathers_name fathersname = fathers_names.delete_if(&:blank?).join(' ') ( fathersname.blank? ) ? '[name not available]' : fathersname end def mothers_names [mother_first_name, mother_middle_name, mother_last_name ] end # Returns string containing study_subject's mother's first, middle and last name # TODO what? no maiden name? def mothers_name mothersname = mothers_names.delete_if(&:blank?).join(' ') ( mothersname.blank? ) ? '[name not available]' : mothersname end def guardians_names [guardian_first_name, guardian_middle_name, guardian_last_name ] end # Returns string containing study_subject's guardian's first, middle and last name def guardians_name guardiansname = guardians_names.delete_if(&:blank?).join(' ') ( guardiansname.blank? ) ? '[name not available]' : guardiansname end # # TODO I hate this. It is revolting. More? Yes, please. # # I don't know if I still need this # commented out 20101014 # uncommented 20101014 def dob # overwrite default dob method for formatting # added to_date to fix sqlite3 quirk which doesn't (why am I using sqlite3?) old comment? # differentiate between times and dates. read_attribute(:dob).try(:to_s,:dob).try(:to_date) end end # class_eval end |