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.
Files changed (2) hide show
  1. data/lib/frosty_meadow.rb +23 -23
  2. 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
- adjectives = (params[:adjectives].nil?)? self.get_default_words[:adjectives] : params[:adjectives]
4
- nouns = (params[:nouns].nil?)? self.get_default_words[:nouns] : params[:nouns]
5
+ words = get_words params
5
6
 
6
- result = "#{adjectives[rand(adjectives.length)]} #{nouns[rand(nouns.length)]}"
7
+ adjectives = words['adjectives']
8
+ nouns = words['nouns']
7
9
 
8
- return (params[:underscored].nil? || params[:underscored] == false)? result : self.to_underscored(result)
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.get_default_words
16
- {:adjectives => ["autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
17
- "summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
18
- "patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
19
- "billowing", "broken", "cold", "damp", "falling", "frosty", "green",
20
- "long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
21
- "red", "rough", "still", "small", "sparkling", "throbbing", "shy",
22
- "wandering", "withered", "wild", "black", "young", "holy", "solitary",
23
- "fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",
24
- "polished", "ancient", "purple", "lively", "nameless"],
25
- :nouns => ["waterfall", "river", "breeze", "moon", "rain", "wind", "sea", "morning",
26
- "snow", "lake", "sunset", "pine", "shadow", "leaf", "dawn", "glitter",
27
- "forest", "hill", "cloud", "meadow", "sun", "glade", "bird", "brook",
28
- "butterfly", "bush", "dew", "dust", "field", "fire", "flower", "firefly",
29
- "feather", "grass", "haze", "mountain", "night", "pond", "darkness",
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frosty_meadow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: