Module: YaKansuji::Formatter::Simple
- Defined in:
- lib/ya_kansuji/formatter/simple.rb
Overview
Simple kansuji formatter
Constant Summary collapse
- DIGITS =
%w(一 二 三 四 五 六 七 八 九).freeze
- UNITS =
([''] + UNIT_EXP3).freeze
Class Method Summary collapse
Class Method Details
.call(num, _options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ya_kansuji/formatter/simple.rb', line 12 def call(num, = {}) return '零' if num.zero? ret = nil chunks = Formatter.split_by_unit4(num) (chunks.size - 1).downto(0) do |idx4| i4 = chunks[idx4] next if i4.zero? ret ||= +'' unit4 = Formatter::UNIT4_UNITS[idx4] if i4 == 1 ret << '一' << unit4 next end divisor = 1000 3.downto(0) do |idx3| i3 = (i4 / divisor) % 10 divisor /= 10 next if i3.zero? unit3 = UNITS[idx3] if i3 == 1 && !unit3.empty? ret << unit3 else ret << DIGITS[i3 - 1] << unit3 end end ret << unit4 end ret || '' end |