frosty_meadow 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/frosty_meadow.rb +32 -30
- metadata +1 -1
data/lib/frosty_meadow.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
module FrostyMeadow
|
4
4
|
module Version
|
5
5
|
MAJOR = 1
|
6
|
-
MINOR =
|
6
|
+
MINOR = 2
|
7
7
|
PATCH = 0
|
8
8
|
|
9
9
|
FULL = [MAJOR, MINOR, PATCH].join('.')
|
@@ -15,45 +15,47 @@ module FrostyMeadow
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
class << self
|
19
|
+
def generate params = {}
|
20
|
+
words = get_words params
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
adjectives = words['adjectives']
|
23
|
+
nouns = words['nouns']
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
result = "#{adjectives[rand(adjectives.length)]} #{nouns[rand(nouns.length)]}"
|
26
|
+
|
27
|
+
return (params[:separator] && self.seperate(result, params[:separator])) || result
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def seperate result, separator
|
31
|
+
result.gsub(/ +/, separator)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def get_words params = {}
|
35
|
+
file_path = File.join(File.dirname(__FILE__), 'data/words.json')
|
36
|
+
file = File.new file_path, "r"
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
file_contents = ""
|
39
|
+
while line = file.gets
|
40
|
+
file_contents << line
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
+
words = JSON.parse(file_contents)
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
words['adjectives'] = params[:adjectives] unless params[:adjectives].nil?
|
46
|
+
words['nouns'] = params[:nouns] unless params[:nouns].nil?
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
return words
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
def generate_hex_name
|
52
|
+
generated_string = self.generate(:separator => '-')
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
return "#{generated_string}-#{self.hex_string}"
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
def hex_string length=5
|
58
|
+
((0..length).map{rand(256).chr}*"").unpack("H*")[0][0,length]
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|