Module: YaKansuji::Formatter::Gov

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

Class Method Summary collapse

Class Method Details

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



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

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

  parts = []
  (UNIT_EXP4.reverse + ['']).each_with_index do |unit4, ridx4|
    i4 = (num / 10_000**(UNIT_EXP4.size - ridx4)).to_i % 10_000
    next if i4.zero?

    if i4 == 1
      parts << "1#{unit4}"
      next
    end
    parts << i4.to_s + unit4
  end
  parts.join(', ')
end