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
- #to_label ⇒ Object
Class Method Details
.from_registered_user(a_user) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/individual.rb', line 23 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
12 13 14 |
# File 'app/models/individual.rb', line 12 def after_initialize self.salt ||= Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s) end |
#create_party ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/individual.rb', line 38 def create_party unless self.party pty = Party.new pty.description = [current_personal_title, current_first_name, current_last_name].join(' ').strip pty.business_party = self pty.save self.party = pty self.save end end |
#destroy_party ⇒ Object
56 57 58 59 60 |
# File 'app/models/individual.rb', line 56 def destroy_party if self.party self.party.destroy end end |
#formatted_ssn_label ⇒ Object
19 20 21 |
# File 'app/models/individual.rb', line 19 def formatted_ssn_label (self.ssn_last_four.blank?) ? "" : "XXX-XX-#{self.ssn_last_four}" end |
#save_party ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/individual.rb', line 49 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 |
#to_label ⇒ Object
62 63 64 |
# File 'app/models/individual.rb', line 62 def to_label "#{current_first_name} #{current_last_name}" end |