Module: YaKansuji::Formatter::Gov

Defined in:
lib/ya_kansuji/formatter/gov.rb

Overview

Formatter for Japan government-style kansuji

Class Method Summary collapse

Class Method Details

.call(num, _options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ya_kansuji/formatter/gov.rb', line 9

def call(num, _options = {})
  return '0' if num.zero?

  parts = []
  chunks = Formatter.split_by_unit4(num)
  (chunks.size - 1).downto(0) do |idx4|
    i4 = chunks[idx4]
    next if i4.zero?

    unit4 = Formatter::UNIT4_UNITS[idx4]
    if i4 == 1
      parts << "1#{unit4}"
      next
    end
    parts << (i4.to_s + unit4)
  end
  parts.join(', ')
end