in bijection-core/src/main/scala/com/twitter/bijection/EnglishInt.scala [17:67]
def apply(num: Int): EnglishInt = EnglishInt(toEnglish(num).get)
override def invert(s: EnglishInt): Int = fromEnglish(s.get).get
}
val (t, d, k, m, g) = (10, 100, 1000, 1000 * 1000, 1000 * 1000 * 1000)
val units = Map(
0 -> "zero",
1 -> "one",
2 -> "two",
3 -> "three",
4 -> "four",
5 -> "five",
6 -> "six",
7 -> "seven",
8 -> "eight",
9 -> "nine"
)
val tens = Map(
t -> "ten",
20 -> "twenty",
30 -> "thirty",
40 -> "forty",
50 -> "fifty",
60 -> "sixty",
70 -> "seventy",
80 -> "eighty",
90 -> "ninety"
)
val teens = Map(
t -> "ten",
11 -> "eleven",
12 -> "twelve",
13 -> "thirteen",
14 -> "fourteen",
15 -> "fifteen",
16 -> "sixteen",
17 -> "seventeen",
18 -> "eighteen",
19 -> "nineteen"
)
val tenmult = Map(d -> "hundred", k -> "thousand", m -> "million", g -> "billion")
val all = units ++ tens ++ teens ++ tenmult
val word2num: Map[String, Int] = (units ++ tens ++ teens ++ tenmult).map(kv => (kv._2, kv._1))
val s = " "
// a helper function that converts num of type Int to a String
// num belongs to exactly one of several bins
// [0,20], [20,d], [d,k], [k,m],[m,g]
// given the bin, we divide by suitable divisor to obtain quotient & remainder
// the quotient & remainder are converted to Enmglish recurisively
private def toEnglish(num: Int): Option[String] = {