CouponCode v0.1.3 CouponCode View Source
This module implements a coupon generating algorithm described here. With inspiration from the ruby version.
Link to this section Summary
Functions
Generates a coupon code with the specified number of parts
Validates a coupon code with the specified number of parts
Link to this section Functions
Link to this function
generate(options \\ [parts: 3])
View Source
generate(options \\ [parts: 3])
View Source
generate([...]) :: String.t()
generate([...]) :: String.t()
Generates a coupon code with the specified number of parts.
Examples
iex> #Seeding data so that example works
iex> :rand.seed(:exsplus, {101, 102, 103})
iex> CouponCode.generate()
"ALCB-J7Q6-15UB"
iex> CouponCode.generate([parts: 5])
"T59C-WMAD-KFEM-XQX2-NY4K"
Link to this function
validate(text, num_parts \\ 3) View Source
Validates a coupon code with the specified number of parts.
Examples
iex> CouponCode.validate("TPV1-EHPN-ZVKT")
{:ok, "TPV1-EHPN-2VKT"}