class Pickaname::Robot

Constants

COMMON
DARK
FIRSTNAME
FUNNY
LASTNAME
PREFIX
PREFIX_SIZE
SUFFIX
SUFFIX_SIZE
TIMEOUT_IN_SECONDS

Attributes

name[R]

Public Class Methods

celebrity(length: nil) click to toggle source
# File lib/pickaname.rb, line 78
def self.celebrity(length: nil)
  begin
    Timeout::timeout(TIMEOUT_IN_SECONDS) do
      @name = FIRSTNAME.sample(PREFIX_SIZE).join << LASTNAME.sample(SUFFIX_SIZE).join
      while length
        break if @name.length == length
        @name = FIRSTNAME.sample(PREFIX_SIZE).join << LASTNAME.sample(SUFFIX_SIZE).join
      end
      return @name
    end
  rescue Timeout::Error
    random_letters(length: length)
  end
end
common(length: nil) click to toggle source

def self.pseudo

@name = PREFIX.sample(PREFIX_SIZE).join << SUFFIX.sample(SUFFIX_SIZE).join

end

# File lib/pickaname.rb, line 33
def self.common(length: nil)
  begin
    Timeout::timeout(TIMEOUT_IN_SECONDS) do
      @name = COMMON.sample(PREFIX_SIZE).join << COMMON.sample(SUFFIX_SIZE).join
      while length
        break if @name.length == length
        @name = COMMON.sample(PREFIX_SIZE).join << COMMON.sample(SUFFIX_SIZE).join
      end
      return @name
    end
  rescue Timeout::Error
    random_letters(length: length)
  end
end
dark(length: nil) click to toggle source
# File lib/pickaname.rb, line 63
def self.dark(length: nil)
  begin
    Timeout::timeout(TIMEOUT_IN_SECONDS) do
      @name = COMMON.sample(PREFIX_SIZE).join << DARK.sample(SUFFIX_SIZE).join
      while length
        break if @name.length == length
        @name = COMMON.sample(PREFIX_SIZE).join << DARK.sample(SUFFIX_SIZE).join
      end
      return @name
    end
  rescue Timeout::Error
    random_letters(length: length)
  end
end
funny(length: nil) click to toggle source
# File lib/pickaname.rb, line 48
def self.funny(length: nil)
  begin
    Timeout::timeout(TIMEOUT_IN_SECONDS) do
      @name = COMMON.sample(PREFIX_SIZE).join << FUNNY.sample(SUFFIX_SIZE).join
      while length
        break if @name.length == length
        @name = COMMON.sample(PREFIX_SIZE).join << FUNNY.sample(SUFFIX_SIZE).join
      end
      return @name
    end
  rescue Timeout::Error
    random_letters(length: length)
  end
end
new() click to toggle source
# File lib/pickaname.rb, line 25
def initialize()
  @name = random_str
end
random_letters(length: 8) click to toggle source
# File lib/pickaname.rb, line 93
def self.random_letters(length: 8)
  record = Robot.new
  begin
    Timeout::timeout(TIMEOUT_IN_SECONDS) do
      @name = record.random_str(length)
      while length
        break if @name.length == length
        @name = record.random_str(length)
      end
      return @name
    end
  rescue Timeout::Error
    puts "Timeout: No results found"
  end
end

Public Instance Methods

random_str(length = 8) click to toggle source
# File lib/pickaname.rb, line 109
def random_str(length = 8)
  return Array.new(length){[*"a".."z", *"0".."9"].sample}.join
end