Created
May 24, 2010 21:17
-
-
Save hosh/412435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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