frosty_meadow 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/frosty_meadow.rb +23 -23
- metadata +1 -1
data/lib/frosty_meadow.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
class FrostyMeadow
|
2
4
|
def self.generate params = {}
|
3
|
-
|
4
|
-
nouns = (params[:nouns].nil?)? self.get_default_words[:nouns] : params[:nouns]
|
5
|
+
words = get_words params
|
5
6
|
|
6
|
-
|
7
|
+
adjectives = words['adjectives']
|
8
|
+
nouns = words['nouns']
|
7
9
|
|
8
|
-
|
10
|
+
result = "#{adjectives[rand(adjectives.length)]} #{nouns[rand(nouns.length)]}"
|
11
|
+
|
12
|
+
return (params[:underscored] && self.to_underscored(result)) || result
|
9
13
|
end
|
10
14
|
|
11
15
|
def self.to_underscored result
|
12
16
|
result.gsub(/ +/, '_')
|
13
17
|
end
|
14
18
|
|
15
|
-
def self.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"snowflake", "silence", "sound", "sky", "shape", "surf", "thunder",
|
31
|
-
"violet", "water", "wildflower", "wave", "water", "resonance", "sun",
|
32
|
-
"wood", "dream", "cherry", "tree", "fog", "frost", "voice", "paper",
|
33
|
-
"frog", "smoke", "star"]}
|
19
|
+
def self.get_words params = {}
|
20
|
+
file_path = File.join(File.dirname(__FILE__), 'data/words.json')
|
21
|
+
file = File.new file_path, "r"
|
22
|
+
|
23
|
+
file_contents = ""
|
24
|
+
while line = file.gets
|
25
|
+
file_contents << line
|
26
|
+
end
|
27
|
+
|
28
|
+
words = JSON.parse(file_contents)
|
29
|
+
|
30
|
+
words['adjectives'] = params[:adjectives] unless params[:adjectives].nil?
|
31
|
+
words['nouns'] = params[:nouns] unless params[:nouns].nil?
|
32
|
+
|
33
|
+
return words
|
34
34
|
end
|
35
35
|
end
|