Skip to content

Instantly share code, notes, and snippets.

@bigfive
Last active December 21, 2015 17:08
Show Gist options
  • Save bigfive/6337887 to your computer and use it in GitHub Desktop.
Save bigfive/6337887 to your computer and use it in GitHub Desktop.
Tupleize a number.
# app/helpers/application_helper.rb
module ApplicationHelper
def tupleize number
units = {
1 => "single",
2 => "double",
3 => "triple",
4 => "quadruple",
5 => "quintuple",
6 => "sextuple",
7 => "septuple",
8 => "octuple",
9 => "nonuple"
}
tens = {
1 => "decuple",
2 => "vigintuple",
3 => "trigintuple",
4 => "quadragintuple",
5 => "quinquagintuple",
6 => "sexagintuple",
7 => "septuagintuple",
8 => "octogintuple",
9 => "nonagintuple"
}
prefixes = {
0 => '',
1 => 'un',
2 => 'do',
3 => 'tre',
4 => 'quattuor',
5 => 'quin',
6 => 'sex',
7 => 'septen',
8 => 'octo',
9 => 'novem'
}
number = number.to_i
if number < 1
raise "Cannot tupleize #{number}"
elsif number < 10
units[number]
elsif number < 100
prefixes[number%10] + tens[number/10]
else
raise "Cannot tupleize #{number}"
end
end
end
@bigfive
Copy link
Author

bigfive commented Aug 26, 2013

Tupleize a number.
http://en.wikipedia.org/wiki/Tuple

Converts 1 => Single, 2 => Double, 56 => Sexquinquagintuple etc (up to 99)

Use it in your views:

You'll love this <%= tupleize(75) %> storey home.
renders:
You'll love this quinseptuagintuple storey home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment