Class: EgovUtils::Person

Inherits:
ApplicationRecord show all
Defined in:
app/models/egov_utils/person.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Person

Returns a new instance of Person.



20
21
22
23
24
25
26
# File 'app/models/egov_utils/person.rb', line 20

def initialize(attributes = {})
  if attributes&.fetch(:remote_id, nil).present?
    super(attributes.slice(:remote_id, :person_type))
  else
    super
  end
end

Instance Method Details

#person_entityObject



28
29
30
31
32
33
34
35
# File 'app/models/egov_utils/person.rb', line 28

def person_entity
  case person_type
  when 'natural'
    natural_person
  when 'legal'
    legal_person
  end
end

#person_entity=(entity) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/models/egov_utils/person.rb', line 37

def person_entity=(entity)
  case person_type
  when 'natural'
    self.natural_person = entity
    self.legal_person = nil
  when 'legal'
    self.legal_person = entity
    self.natural_person = nil
  end
end

#residenceObject



48
49
50
# File 'app/models/egov_utils/person.rb', line 48

def residence
  addresses.last
end

#residence=(address) ⇒ Object



52
53
54
# File 'app/models/egov_utils/person.rb', line 52

def residence=(address)
  addresses << address
end

#to_sObject



56
57
58
# File 'app/models/egov_utils/person.rb', line 56

def to_s
  person_entity.to_s
end