module RandomUsername
Constants
- Error
- VERSION
Public Class Methods
adjective(options = {})
click to toggle source
# File lib/random_username.rb, line 6 def self.adjective(options = {}) get_item("adjectives", options) end
get_item(filename, options = {})
click to toggle source
# File lib/random_username.rb, line 20 def self.get_item(filename, options = {}) items = items_from_file(filename) items.select!{ |item| item.length <= options[:max_length] } if options[:max_length] items.select!{ |item| item.length >= options[:min_length] } if options[:min_length] items.sample || fail(RandomUsername::Error, "No words found") end
items_from_file(filename)
click to toggle source
# File lib/random_username.rb, line 27 def self.items_from_file(filename) filepath = File.expand_path("../random_username/#{filename}.txt", __FILE__) File.read(filepath).split("\n") end
noun(options = {})
click to toggle source
# File lib/random_username.rb, line 10 def self.noun(options = {}) get_item("nouns", options) end
username(options = {})
click to toggle source
# File lib/random_username.rb, line 14 def self.username(options = {}) options[:max_length] /= 2 if options[:max_length] options[:min_length] /= 2 if options[:min_length] adjective(options) + noun(options) end