11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/convert_numeral.rb', line 11
def to_chinese_numeral
return TEN_NUMERALS[0] if self == 0
string = self.to_s
total_length = string.length
return convert_separated_by_four_digit(string, total_length) if total_length <= 4
quo, mod = total_length.divmod(4)
limit = (mod == 0) ? quo - 1 : quo
separated_numerals_by_four_digit = (string, limit, mod)
separated_numerals_by_four_digit
.map.with_index do |numeral, index|
converted_string = convert_separated_by_four_digit(numeral, numeral.length, index, limit)
converted_string.empty? ? '' : converted_string + UNITS_GREATER_THAN_TEN_THOUSAND[index]
end
.reverse
.join
end
|