Skip to content

Instantly share code, notes, and snippets.

@hosh
Created May 24, 2010 21:17
Show Gist options
  • Save hosh/412435 to your computer and use it in GitHub Desktop.
Save hosh/412435 to your computer and use it in GitHub Desktop.
class Forgery
class Merchant
PRODUCTS = %w(coffee drink gas donut sandwich icecream cigarette)
PROMOTION_TYPES = [
lambda {
["Buy X P get Y Q free",
[:X, rand(3)+1],
[:Y, rand(4)+1],
[:P, PRODUCTS.rand],
[:Q, PRODUCTS.rand] ]},
lambda {
["Buy X P get Y% off next Q",
[:X, rand(3)+1],
[:Y, (rand(8)+1) * 10],
[:P, PRODUCTS.rand],
[:Q, PRODUCTS.rand] ]},
lambda {
["X% off P",
[:X, (rand(19)+1)*5],
[:P, PRODUCTS.rand] ]},
lambda {
["Buy P get Q free",
[:P, PRODUCTS.rand],
[:Q, PRODUCTS.rand] ]}
]
class << self
def promotion
substitutions = PROMOTION_TYPES.rand.call
text = substitutions.shift
format_forgery(text, substitutions)
end
private
def format_forgery(text, substitutions)
substitutions.inject(text) do |output, substitution|
output.gsub(substitution[0].to_s, substitution[1].to_s)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment