module FrostyMeadow

Public Class Methods

generate(params = {}) click to toggle source
# File lib/frosty_meadow.rb, line 30
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_name(params = {}) click to toggle source
# File lib/frosty_meadow.rb, line 77
def generate_hex_name params = {}
        generated_string = self.generate({:separator => '-'}.merge(params))

        return "#{generated_string}-#{self::Hex.generate}"
end
get_words(params = {}) click to toggle source
# File lib/frosty_meadow.rb, line 45
      def get_words params = {}

              if @@words.empty? || !params[:skip_cache].nil? || params[:from_file] != @@cached_path
                      if params[:from_file].nil?
dictionary_file = params[:metal_mode] ? 'data/metal.json' : 'data/words.json'

                              file_path =  File.join(File.dirname(__FILE__), dictionary_file)
                      else
                              file_path = params[:from_file]
                      end

                      file = File.new file_path, "r"

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

                      words       = JSON.parse(file_contents)

                      @@words       = words
                      @@cached_path = file_path
              else
                      words = @@words
              end

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

              return words
      end
hex_string(length=5) click to toggle source
# File lib/frosty_meadow.rb, line 83
def hex_string length=5
        ((0..length).map{rand(256).chr}*"").unpack("H*")[0][0,length]
end
seperate(result, separator) click to toggle source
# File lib/frosty_meadow.rb, line 41
def seperate result, separator
        result.gsub(/ +/, separator)
end