Last active
December 21, 2015 17:08
-
-
Save bigfive/6337887 to your computer and use it in GitHub Desktop.
Tupleize a number.
This file contains 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.