Class: Individual
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Individual
- Defined in:
- app/models/individual.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #create_party ⇒ Object
- #destroy_party ⇒ Object
- #formatted_ssn_label ⇒ Object
- #save_party ⇒ Object
- #social_security_number ⇒ Object (also: #ssn)
- #social_security_number=(ssn) ⇒ Object
- #to_label ⇒ Object
Class Method Details
.from_registered_user(a_user) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/individual.rb', line 35 def self.from_registered_user(a_user) ind = Individual.new ind.current_first_name = a_user.first_name ind.current_last_name = a_user.last_name #this is necessary because this is where the callback creates the party instance. ind.save a_user.party = ind.party a_user.save ind.save #this is necessary because save returns a boolean, not the saved object return ind end |
Instance Method Details
#after_initialize ⇒ Object
15 16 17 |
# File 'app/models/individual.rb', line 15 def after_initialize self.salt ||= Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s) end |
#create_party ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/models/individual.rb', line 50 def create_party pty = Party.new pty.description = [current_personal_title, current_first_name, current_last_name].join(' ').strip pty.business_party = self pty.save self.save end |
#destroy_party ⇒ Object
65 66 67 68 69 |
# File 'app/models/individual.rb', line 65 def destroy_party if self.party self.party.destroy end end |
#formatted_ssn_label ⇒ Object
31 32 33 |
# File 'app/models/individual.rb', line 31 def formatted_ssn_label (self.ssn_last_four.blank?) ? "" : "XXX-XX-#{self.ssn_last_four}" end |
#save_party ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/individual.rb', line 58 def save_party if self.party.description.blank? && (!current_first_name.blank? && !current_last_name.blank?) self.party.description = [current_personal_title, current_first_name, current_last_name].join(' ').strip self.party.save end end |
#social_security_number ⇒ Object Also known as: ssn
25 26 27 |
# File 'app/models/individual.rb', line 25 def Individual.decrypt_encrypted_ssn(self.encrypted_ssn) end |
#social_security_number=(ssn) ⇒ Object
19 20 21 22 23 |
# File 'app/models/individual.rb', line 19 def (ssn) self.ssn_last_four = ssn[-4..-1] self.encrypted_ssn = Individual.encrypt_encrypted_ssn(ssn) self.save end |
#to_label ⇒ Object
71 72 73 |
# File 'app/models/individual.rb', line 71 def to_label "#{current_first_name} #{current_last_name}" end |