Class: MoveToGo::Person
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- MoveToGo::Person
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/move-to-go/model/person.rb
Instance Attribute Summary collapse
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#organization ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
Instance Method Summary collapse
-
#alternative_email ⇒ Object
:attr_accessor: alternative_email.
-
#currently_employed ⇒ Object
:attr_accessor: currently_employed.
-
#direct_phone_number ⇒ Object
:attr_accessor: direct_phone_number.
-
#email ⇒ Object
:attr_accessor: email.
-
#fax_phone_number ⇒ Object
:attr_accessor: fax_phone_number.
-
#first_name ⇒ Object
:attr_accessor: first_name.
- #get_import_rows ⇒ Object
-
#has_mail_consent ⇒ Object
:attr_accessor: has_mail_consent.
-
#home_phone_number ⇒ Object
:attr_accessor: home_phone_number.
-
#id ⇒ Object
:attr_accessor: id.
-
#initialize(opt = nil) ⇒ Person
constructor
A new instance of Person.
-
#integration_id ⇒ Object
:attr_accessor: integration_id.
-
#last_name ⇒ Object
:attr_accessor: last_name.
-
#mobile_phone_number ⇒ Object
:attr_accessor: mobile_phone_number.
- #parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
-
#position ⇒ Object
:attr_accessor: position.
-
#postal_address ⇒ Object
:attr_accessor: postal_address.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #set_organization_reference=(org) ⇒ Object
- #tags ⇒ Object
- #to_reference ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
- #with_postal_address {|@postal_address| ... } ⇒ Object
- #with_source {|@source| ... } ⇒ Object
Methods included from SerializeHelper
#serialize, #serialize_to_file
Methods included from ModelHasCustomFields
Methods included from ModelHasTags
Methods inherited from CanBecomeImmutable
immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable
Constructor Details
#initialize(opt = nil) ⇒ Person
Returns a new instance of Person.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/move-to-go/model/person.rb', line 86 def initialize(opt = nil) @currently_employed = true if opt != nil serialize_variables.each do |myattr| val = opt[myattr[:id]] instance_variable_set("@" + myattr[:id].to_s, val) if val != nil end end set_tag 'Import' end |
Instance Attribute Details
#custom_values ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
84 85 86 |
# File 'lib/move-to-go/model/person.rb', line 84 def custom_values @custom_values end |
#organization ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
84 85 86 |
# File 'lib/move-to-go/model/person.rb', line 84 def organization @organization end |
Instance Method Details
#alternative_email ⇒ Object
:attr_accessor: alternative_email
72 |
# File 'lib/move-to-go/model/person.rb', line 72 immutable_accessor :alternative_email |
#currently_employed ⇒ Object
:attr_accessor: currently_employed
78 |
# File 'lib/move-to-go/model/person.rb', line 78 immutable_accessor :currently_employed |
#direct_phone_number ⇒ Object
:attr_accessor: direct_phone_number
54 |
# File 'lib/move-to-go/model/person.rb', line 54 immutable_accessor :direct_phone_number |
#email ⇒ Object
:attr_accessor: email
69 |
# File 'lib/move-to-go/model/person.rb', line 69 immutable_accessor :email |
#fax_phone_number ⇒ Object
:attr_accessor: fax_phone_number
57 |
# File 'lib/move-to-go/model/person.rb', line 57 immutable_accessor :fax_phone_number |
#first_name ⇒ Object
:attr_accessor: first_name
48 |
# File 'lib/move-to-go/model/person.rb', line 48 immutable_accessor :first_name |
#get_import_rows ⇒ Object
166 167 168 169 170 |
# File 'lib/move-to-go/model/person.rb', line 166 def get_import_rows (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p| map_to_row p end end |
#has_mail_consent ⇒ Object
:attr_accessor: has_mail_consent
81 |
# File 'lib/move-to-go/model/person.rb', line 81 immutable_accessor :has_mail_consent |
#home_phone_number ⇒ Object
:attr_accessor: home_phone_number
63 |
# File 'lib/move-to-go/model/person.rb', line 63 immutable_accessor :home_phone_number |
#id ⇒ Object
:attr_accessor: id
42 |
# File 'lib/move-to-go/model/person.rb', line 42 immutable_accessor :id |
#integration_id ⇒ Object
:attr_accessor: integration_id
45 |
# File 'lib/move-to-go/model/person.rb', line 45 immutable_accessor :integration_id |
#last_name ⇒ Object
:attr_accessor: last_name
51 |
# File 'lib/move-to-go/model/person.rb', line 51 immutable_accessor :last_name |
#mobile_phone_number ⇒ Object
:attr_accessor: mobile_phone_number
60 |
# File 'lib/move-to-go/model/person.rb', line 60 immutable_accessor :mobile_phone_number |
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/move-to-go/model/person.rb', line 187 def parse_name_to_firstname_lastname_se(name, when_missing = '') if name.nil? or name.empty? @first_name = when_missing return end splitted = name.split(' ') @first_name = splitted[0] if splitted.length > 1 @last_name = splitted.drop(1).join(' ') end end |
#position ⇒ Object
:attr_accessor: position
66 |
# File 'lib/move-to-go/model/person.rb', line 66 immutable_accessor :position |
#postal_address ⇒ Object
:attr_accessor: postal_address
75 |
# File 'lib/move-to-go/model/person.rb', line 75 immutable_accessor :postal_address |
#serialize_name ⇒ Object
126 127 128 |
# File 'lib/move-to-go/model/person.rb', line 126 def serialize_name "Person" end |
#serialize_variables ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/move-to-go/model/person.rb', line 130 def serialize_variables [ {:id => :id, :type => :string}, {:id => :integration_id, :type => :string}, {:id => :source, :type => :source_ref}, {:id => :first_name, :type => :string}, {:id => :last_name, :type => :string}, {:id => :direct_phone_number, :type => :string}, {:id => :fax_phone_number, :type => :string}, {:id => :mobile_phone_number, :type => :string}, {:id => :home_phone_number, :type => :string}, {:id => :position, :type => :string}, {:id => :tags, :type => :tags}, {:id => :email, :type => :string}, {:id => :alternative_email, :type => :string}, {:id => :postal_address, :type => :address}, {:id => :custom_values, :type => :custom_values}, {:id => :currently_employed, :type => :bool}, {:id => :has_mail_consent, :type => :bool}, {:id => :organization, :type => :organization_reference}, ] end |
#set_organization_reference=(org) ⇒ Object
98 99 100 |
# File 'lib/move-to-go/model/person.rb', line 98 def set_organization_reference=(org) @organization = OrganizationReference.from_organization(org) end |
#tags ⇒ Object
122 123 124 |
# File 'lib/move-to-go/model/person.rb', line 122 def @tags end |
#to_reference ⇒ Object
159 160 161 162 163 164 |
# File 'lib/move-to-go/model/person.rb', line 159 def to_reference() reference = PersonReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
172 173 174 |
# File 'lib/move-to-go/model/person.rb', line 172 def to_s return "#{first_name} #{last_name}" end |
#validate ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/move-to-go/model/person.rb', line 176 def validate error = String.new if (@first_name.nil? || @first_name.empty?) && (@last_name.nil? || @last_name.empty?) error = "A firstname or lastname is required for person.\n#{serialize()}" end return error end |
#with_postal_address {|@postal_address| ... } ⇒ Object
107 108 109 110 |
# File 'lib/move-to-go/model/person.rb', line 107 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
117 118 119 120 |
# File 'lib/move-to-go/model/person.rb', line 117 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |