Class: MoveToGo::Coworker
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- MoveToGo::Coworker
- Includes:
- SerializeHelper
- Defined in:
- lib/move-to-go/model/coworker.rb
Instance Method Summary collapse
- #==(that) ⇒ Object
-
#direct_phone_number ⇒ Object
:attr_accessor: direct_phone_number.
-
#email ⇒ Object
:attr_accessor: email.
-
#first_name ⇒ Object
:attr_accessor: first_name.
- #guess_email(domain) ⇒ Object
-
#home_phone_number ⇒ Object
:attr_accessor: home_phone_number.
-
#id ⇒ Object
:attr_accessor: id.
-
#initialize(opt = nil) ⇒ Coworker
constructor
A new instance of Coworker.
-
#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
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #to_email_chars(s) ⇒ Object
- #to_reference ⇒ Object
- #validate ⇒ Object
Methods included from SerializeHelper
#get_import_rows, #serialize, #serialize_to_file
Methods inherited from CanBecomeImmutable
immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable
Constructor Details
#initialize(opt = nil) ⇒ Coworker
Returns a new instance of Coworker.
36 37 38 39 40 41 42 43 |
# File 'lib/move-to-go/model/coworker.rb', line 36 def initialize(opt = nil) 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 end |
Instance Method Details
#==(that) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/move-to-go/model/coworker.rb', line 65 def ==(that) if that.nil? return false end if that.is_a? Coworker return @integration_id == that.integration_id end return false end |
#direct_phone_number ⇒ Object
:attr_accessor: direct_phone_number
26 |
# File 'lib/move-to-go/model/coworker.rb', line 26 immutable_accessor :direct_phone_number |
#email ⇒ Object
:attr_accessor: email
14 |
# File 'lib/move-to-go/model/coworker.rb', line 14 immutable_accessor :email |
#first_name ⇒ Object
:attr_accessor: first_name
18 |
# File 'lib/move-to-go/model/coworker.rb', line 18 immutable_accessor :first_name |
#guess_email(domain) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/move-to-go/model/coworker.rb', line 94 def guess_email(domain) return '' if @last_name.nil? || @last_name.empty? return '' if @first_name.nil? || @first_name.empty? firstname = to_email_chars @first_name.downcase lastname = to_email_chars @last_name.downcase return "#{firstname}.#{lastname}@#{domain}" end |
#home_phone_number ⇒ Object
:attr_accessor: home_phone_number
34 |
# File 'lib/move-to-go/model/coworker.rb', line 34 immutable_accessor :home_phone_number |
#id ⇒ Object
:attr_accessor: id
6 |
# File 'lib/move-to-go/model/coworker.rb', line 6 immutable_accessor :id |
#integration_id ⇒ Object
:attr_accessor: integration_id
10 |
# File 'lib/move-to-go/model/coworker.rb', line 10 immutable_accessor :integration_id |
#last_name ⇒ Object
:attr_accessor: last_name
22 |
# File 'lib/move-to-go/model/coworker.rb', line 22 immutable_accessor :last_name |
#mobile_phone_number ⇒ Object
:attr_accessor: mobile_phone_number
30 |
# File 'lib/move-to-go/model/coworker.rb', line 30 immutable_accessor :mobile_phone_number |
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/move-to-go/model/coworker.rb', line 77 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
61 62 63 |
# File 'lib/move-to-go/model/coworker.rb', line 61 def serialize_name "Coworker" end |
#serialize_variables ⇒ Object
45 46 47 48 49 50 |
# File 'lib/move-to-go/model/coworker.rb', line 45 def serialize_variables [ :id, :integration_id, :email, :first_name, :last_name, :direct_phone_number, :mobile_phone_number, :home_phone_number ].map {|p| { :id => p, :type => :string } } end |
#to_email_chars(s) ⇒ Object
90 91 92 |
# File 'lib/move-to-go/model/coworker.rb', line 90 def to_email_chars(s) s.tr " åäöèé", "-aaoee" end |
#to_reference ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/move-to-go/model/coworker.rb', line 52 def to_reference reference = CoworkerReference.new reference.id = @id reference.integration_id = @integration_id reference.heading = "#{@first_name} #{@last_name}".strip return reference end |
#validate ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/move-to-go/model/coworker.rb', line 103 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 coworker.\n#{serialize()}" end return error end |