Class: GoImport::Person
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- GoImport::Person
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/go_import/model/person.rb
Instance Attribute Summary collapse
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#organization ⇒ Object
you add custom values by using ModelHasCustomFields#set_custom_value.
Instance Method Summary collapse
- #get_import_rows ⇒ Object
-
#initialize(opt = nil) ⇒ Person
constructor
A new instance of Person.
- #parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
- #serialize_name ⇒ Object
- #serialize_variables ⇒ 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.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/go_import/model/person.rb', line 51 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
49 50 51 |
# File 'lib/go_import/model/person.rb', line 49 def custom_values @custom_values end |
#organization ⇒ Object
you add custom values by using ModelHasCustomFields#set_custom_value
49 50 51 |
# File 'lib/go_import/model/person.rb', line 49 def organization @organization end |
Instance Method Details
#get_import_rows ⇒ Object
130 131 132 133 134 |
# File 'lib/go_import/model/person.rb', line 130 def get_import_rows (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p| map_to_row p end end |
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/go_import/model/person.rb', line 151 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 |
#serialize_name ⇒ Object
91 92 93 |
# File 'lib/go_import/model/person.rb', line 91 def serialize_name "Person" end |
#serialize_variables ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/go_import/model/person.rb', line 95 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 |
#tags ⇒ Object
87 88 89 |
# File 'lib/go_import/model/person.rb', line 87 def @tags end |
#to_reference ⇒ Object
123 124 125 126 127 128 |
# File 'lib/go_import/model/person.rb', line 123 def to_reference() reference = PersonReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
136 137 138 |
# File 'lib/go_import/model/person.rb', line 136 def to_s return "#{first_name} #{last_name}" end |
#validate ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/go_import/model/person.rb', line 140 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
72 73 74 75 |
# File 'lib/go_import/model/person.rb', line 72 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
82 83 84 85 |
# File 'lib/go_import/model/person.rb', line 82 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |