Sha256: 6b11301db39ea88c63e7528bdd6776a06baeec2089c9b9dca0397e6e24df404f

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

module Faker
  module Internet
    extend ModuleUtils
    extend self

    def email(name = nil)
      [ user_name(name), domain_name ].join('@')
    end

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

    def user_name(name = nil)
      if name
        parts = ArrayUtils.shuffle(name.scan(/\w+/)).join(ArrayUtils.rand(%w(. _)))
        parts.downcase!
        parts
      else
        case rand(2)
        when 0
          Name.first_name.gsub(/\W/, '').downcase
        when 1
          parts = [ Name.first_name, Name.last_name ].each {|n| n.gsub!(/\W/, '') }
          parts = parts.join ArrayUtils.rand(%w(. _))
          parts.downcase!
          parts
        end
      end
    end

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

    def domain_word
      dw = Company.name.split(' ').first
      dw.gsub!(/\W/, '')
      dw.downcase!
      dw
    end

    def domain_suffix
      DOMAIN_SUFFIXES.rand
    end

    HOSTS = k %w(gmail.com yahoo.com hotmail.com)
    DOMAIN_SUFFIXES = k %w(co.uk com us uk ca biz info name)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ffaker-1.0.0 lib/ffaker/internet.rb
ffaker-0.4.0 lib/ffaker/internet.rb
ffaker-0.3.7 lib/ffaker/internet.rb
ffaker-0.3.6 lib/ffaker/internet.rb
ffaker-0.3.5 lib/ffaker/internet.rb
ffaker-0.3.4 lib/ffaker/internet.rb
ffaker-0.3.3 lib/ffaker/internet.rb
ffaker-0.3.2 lib/faker/internet.rb