Module: FFaker::InternetSE

Extended by:
InternetSE, ModuleUtils
Includes:
Internet
Included in:
InternetSE
Defined in:
lib/ffaker/internet_se.rb

Constant Summary collapse

BYTE =
[*'0'..'255']
HOSTS =
%w(gmail.com yahoo.com hotmail.com spray.se passagen.se)
DOMAIN_SUFFIXES =
%w(se nu com)
DISPOSABLE_HOSTS =
%w(mailinator.com suremail.info spamherelots.com binkmail.com safetymail.info)
SLUG_DELIMITERS =
%w(- _ .)

Constants included from Internet

FFaker::Internet::SAFE_DOMAIN_SUFFIXES

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Methods included from Internet

#password, #safe_email

Instance Method Details

#company_name_single_wordObject


86
87
88
# File 'lib/ffaker/internet_se.rb', line 86

def company_name_single_word
  CompanySE.name.split(' ').first
end

#disposable_email(name = nil) ⇒ Object

Returns an email address of an online disposable email service (like tempinbox.com). you can really send an email to these addresses an access it by going to the service web pages.


25
26
27
# File 'lib/ffaker/internet_se.rb', line 25

def disposable_email(name = nil)
  "#{user_name(name)}@#{DISPOSABLE_HOSTS.sample}"
end

#domain_nameObject


75
76
77
# File 'lib/ffaker/internet_se.rb', line 75

def domain_name
  "#{domain_word}.#{domain_suffix}"
end

#domain_suffixObject


90
91
92
# File 'lib/ffaker/internet_se.rb', line 90

def domain_suffix
  DOMAIN_SUFFIXES.sample
end

#domain_wordObject


79
80
81
82
83
84
# File 'lib/ffaker/internet_se.rb', line 79

def domain_word
  company_name_single_word.tap do |dw|
    dw.gsub!(/\W/, '')
    dw.downcase!
  end
end

#email(name = nil) ⇒ Object


18
19
20
# File 'lib/ffaker/internet_se.rb', line 18

def email(name = nil)
  "#{user_name(name)}@#{domain_name}"
end

#free_email(name = nil) ⇒ Object


29
30
31
# File 'lib/ffaker/internet_se.rb', line 29

def free_email(name = nil)
  "#{user_name(name)}@#{HOSTS.sample}"
end

#http_urlObject


98
99
100
# File 'lib/ffaker/internet_se.rb', line 98

def http_url
  uri('http')
end

#ip_v4_addressObject


102
103
104
# File 'lib/ffaker/internet_se.rb', line 102

def ip_v4_address
  (1..4).map { BYTE.sample }.join('.')
end

#join_to_user_name(array_parts) ⇒ Object


70
71
72
73
# File 'lib/ffaker/internet_se.rb', line 70

def join_to_user_name(array_parts)
  join_char = %w(. _).sample
  array_parts.map(&:downcase).join(join_char)
end

#login_user_nameObject

Used to fake login names were dot is not allowed


34
35
36
# File 'lib/ffaker/internet_se.rb', line 34

def 
  user_name.tr('.', '')
end

#slug(words = nil, glue = nil) ⇒ Object


106
107
108
109
110
# File 'lib/ffaker/internet_se.rb', line 106

def slug(words = nil, glue = nil)
  glue ||= SLUG_DELIMITERS.sample

  (words || FFaker::Lorem.words(2).join(' ')).gsub(' ', glue).downcase
end

#uri(protocol) ⇒ Object


94
95
96
# File 'lib/ffaker/internet_se.rb', line 94

def uri(protocol)
  "#{protocol}://#{domain_name}"
end

#user_name(name = nil) ⇒ Object

Mostly used for email creation


39
40
41
42
# File 'lib/ffaker/internet_se.rb', line 39

def user_name(name = nil)
  return user_name_from_name(name) if name
  user_name_random
end

#user_name_from_name(name) ⇒ Object


65
66
67
68
# File 'lib/ffaker/internet_se.rb', line 65

def user_name_from_name(name)
  array_parts = name.scan(/\w+/).shuffle
  join_to_user_name(array_parts)
end

#user_name_randomObject


44
45
46
47
48
49
50
51
# File 'lib/ffaker/internet_se.rb', line 44

def user_name_random
  variant = rand(2)
  case variant
  when 0 then user_name_variant_short
  when 1 then user_name_variant_long
  else        user_name_variant_short
  end
end

#user_name_variant_longObject


53
54
55
56
57
# File 'lib/ffaker/internet_se.rb', line 53

def user_name_variant_long
  array_parts = [NameSE.first_name, NameSE.last_name]
  array_parts.map! { |word| word.gsub(/\W/, '') }
  join_to_user_name(array_parts)
end

#user_name_variant_shortObject


59
60
61
62
63
# File 'lib/ffaker/internet_se.rb', line 59

def user_name_variant_short
  array_parts = [NameSE.first_name]
  array_parts.map! { |word| word.gsub(/\W/, '') }
  join_to_user_name(array_parts)
end