Repository URL to install this package:
|
Version:
0.0.1 ▾
|
require "carnival/version"
module Carnival
def self.noun
get_item("items")
end
def self.adj
get_item("adj")
end
def self.a_name
format("%A%N")
end
def self.a_hyp_name
format("%A-%N")
end
def self.a_name_rand
format("%A%N-%II")
end
def self.a_hyp_name_rand
format("%A-%N-%II")
end
# Accepts a string of any pattern and replaces the keywords below:
# %N - Gets replaced with a random noun
# %A - Gets replaced with a random adj
# %I..I - Get replaced with a random number that's the same length as the num of I's
#
# All keywords are repeatable
def self.format(formatString)
finalString = formatString
while not finalString.index("%A").nil?
finalString = finalString.sub("%A", adj)
end
while not finalString.index("%N").nil?
finalString = finalString.sub("%N", noun)
end
matchArray = finalString.scan(/%I+/)
unless matchArray.nil?
matchArray.each do |match|
length = match.size - 1
num = rand(10 ** length).to_s.rjust(length,'0')
finalString = finalString.sub(match, num)
end
end
return finalString
end
def self.get_item(filename)
File.read(File.expand_path("../carnival/#{filename}.txt", __FILE__)).split("\n").sample.strip.downcase
end
end