Module: OmniContacts::ParseUtils

Included in:
Importer::Facebook, Importer::Gmail, Importer::Hotmail, Importer::Linkedin, Importer::Outlook, Importer::Yahoo
Defined in:
lib/omnicontacts/parse_utils.rb

Instance Method Summary collapse

Instance Method Details

#birthday_format(month, day, year) ⇒ Object

return has of birthday day, month and year



5
6
7
8
9
# File 'lib/omnicontacts/parse_utils.rb', line 5

def birthday_format month, day, year
  return {:day => day.to_i, :month => month.to_i, :year => year.to_i}if year && month && day
  return {:day => day.to_i, :month => month.to_i, :year => nil} if !year && month && day
  return nil if (!year && !month) || (!year && !day)
end

#email_to_name(username_or_email) ⇒ Object

create a username/name from a given email



29
30
31
32
33
34
35
36
37
38
# File 'lib/omnicontacts/parse_utils.rb', line 29

def email_to_name username_or_email
  username_or_email = username_or_email.split('@').first if username_or_email.include?('@')
  if group = (/(?<first>[a-z|A-Z]+)[\.|_](?<last>[a-z|A-Z]+)/).match(username_or_email)
    first_name = normalize_name(group[:first])
    last_name = normalize_name(group[:last])
    return first_name, last_name, "#{first_name} #{last_name}"
  end
  username = normalize_name(username_or_email)
  return username, nil, username
end

#full_name(first_name, last_name) ⇒ Object

create a full name given the individual first and last name



21
22
23
24
25
26
# File 'lib/omnicontacts/parse_utils.rb', line 21

def full_name first_name, last_name
  return "#{first_name} #{last_name}" if first_name && last_name
  return "#{first_name}" if first_name && !last_name
  return "#{last_name}" if !first_name && last_name
  return nil
end

#image_url_from_email(email) ⇒ Object

create an image_url from a gmail or yahoo email id.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/omnicontacts/parse_utils.rb', line 41

def image_url_from_email email
  return nil if email.nil? || !email.include?('@')
  username, domain = *(email.split('@'))
  return nil if username.nil? or domain.nil?
  gmail_base_url = "https://profiles.google.com/s2/photos/profile/"
  yahoo_base_url = "https://img.msg.yahoo.com/avatar.php?yids="
  if domain.include?('gmail')
    image_url = gmail_base_url + username
  elsif domain.include?('yahoo')
    image_url = yahoo_base_url + username
  end
  image_url
end

#normalize_name(name) ⇒ Object

normalize the name



12
13
14
15
16
17
18
# File 'lib/omnicontacts/parse_utils.rb', line 12

def normalize_name name
  return nil if name.nil?
  name.chomp!
  name.squeeze!(' ')
  name.strip!
  return name
end