Module: FrostyMeadow

Defined in:
lib/frosty_meadow.rb

Defined Under Namespace

Modules: Hex, Version

Class Method Summary collapse

Class Method Details

.generate(params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/frosty_meadow.rb', line 27

def generate params = {}
	words = get_words params

	adjectives = words['adjectives']
	nouns      = words['nouns']

	result = "#{adjectives[rand(adjectives.length)]} #{nouns[rand(nouns.length)]}"
	
	return (params[:separator] && self.seperate(result, params[:separator])) || result
end

.generate_hex_nameObject



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

def generate_hex_name 
	generated_string = self.generate(:separator => '-')

	return "#{generated_string}-#{self::Hex.generate}"
end

.get_words(params = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/frosty_meadow.rb', line 42

def get_words params = {}
	file_path =  File.join(File.dirname(__FILE__), 'data/words.json')
	file = File.new file_path, "r"

	file_contents = ""
	while line = file.gets
		file_contents << line
	end

	words = JSON.parse(file_contents)

	words['adjectives'] = params[:adjectives] unless params[:adjectives].nil?
	words['nouns'] = params[:nouns] unless params[:nouns].nil?

	return words
end

.hex_string(length = 5) ⇒ Object



65
66
67
# File 'lib/frosty_meadow.rb', line 65

def hex_string length=5
	((0..length).map{rand(256).chr}*"").unpack("H*")[0][0,length]
end

.seperate(result, separator) ⇒ Object



38
39
40
# File 'lib/frosty_meadow.rb', line 38

def seperate result, separator
	result.gsub(/ +/, separator)
end