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
-
#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.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/move-to-go/model/person.rb', line 77 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
75 76 77 |
# File 'lib/move-to-go/model/person.rb', line 75 def custom_values @custom_values end |
#organization ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
75 76 77 |
# File 'lib/move-to-go/model/person.rb', line 75 def organization @organization end |
Instance Method Details
#alternative_email ⇒ Object
:attr_accessor: alternative_email
66 |
# File 'lib/move-to-go/model/person.rb', line 66 immutable_accessor :alternative_email |
#currently_employed ⇒ Object
:attr_accessor: currently_employed
72 |
# File 'lib/move-to-go/model/person.rb', line 72 immutable_accessor :currently_employed |
#direct_phone_number ⇒ Object
:attr_accessor: direct_phone_number
48 |
# File 'lib/move-to-go/model/person.rb', line 48 immutable_accessor :direct_phone_number |
#email ⇒ Object
:attr_accessor: email
63 |
# File 'lib/move-to-go/model/person.rb', line 63 immutable_accessor :email |
#fax_phone_number ⇒ Object
:attr_accessor: fax_phone_number
51 |
# File 'lib/move-to-go/model/person.rb', line 51 immutable_accessor :fax_phone_number |
#first_name ⇒ Object
:attr_accessor: first_name
42 |
# File 'lib/move-to-go/model/person.rb', line 42 immutable_accessor :first_name |
#get_import_rows ⇒ Object
156 157 158 159 160 |
# File 'lib/move-to-go/model/person.rb', line 156 def get_import_rows (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p| map_to_row p end end |
#home_phone_number ⇒ Object
:attr_accessor: home_phone_number
57 |
# File 'lib/move-to-go/model/person.rb', line 57 immutable_accessor :home_phone_number |
#id ⇒ Object
:attr_accessor: id
36 |
# File 'lib/move-to-go/model/person.rb', line 36 immutable_accessor :id |
#integration_id ⇒ Object
:attr_accessor: integration_id
39 |
# File 'lib/move-to-go/model/person.rb', line 39 immutable_accessor :integration_id |
#last_name ⇒ Object
:attr_accessor: last_name
45 |
# File 'lib/move-to-go/model/person.rb', line 45 immutable_accessor :last_name |
#mobile_phone_number ⇒ Object
:attr_accessor: mobile_phone_number
54 |
# File 'lib/move-to-go/model/person.rb', line 54 immutable_accessor :mobile_phone_number |
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/move-to-go/model/person.rb', line 177 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
60 |
# File 'lib/move-to-go/model/person.rb', line 60 immutable_accessor :position |
#postal_address ⇒ Object
:attr_accessor: postal_address
69 |
# File 'lib/move-to-go/model/person.rb', line 69 immutable_accessor :postal_address |
#serialize_name ⇒ Object
117 118 119 |
# File 'lib/move-to-go/model/person.rb', line 117 def serialize_name "Person" end |
#serialize_variables ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/move-to-go/model/person.rb', line 121 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 => :organization, :type => :organization_reference}, ] end |
#set_organization_reference=(org) ⇒ Object
89 90 91 |
# File 'lib/move-to-go/model/person.rb', line 89 def set_organization_reference=(org) @organization = OrganizationReference.from_organization(org) end |
#tags ⇒ Object
113 114 115 |
# File 'lib/move-to-go/model/person.rb', line 113 def @tags end |
#to_reference ⇒ Object
149 150 151 152 153 154 |
# File 'lib/move-to-go/model/person.rb', line 149 def to_reference() reference = PersonReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
162 163 164 |
# File 'lib/move-to-go/model/person.rb', line 162 def to_s return "#{first_name} #{last_name}" end |
#validate ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/move-to-go/model/person.rb', line 166 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
98 99 100 101 |
# File 'lib/move-to-go/model/person.rb', line 98 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
108 109 110 111 |
# File 'lib/move-to-go/model/person.rb', line 108 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |