Module: YaKansuji::Formatter::JudicV

Defined in:
lib/ya_kansuji/formatter/judic_v.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
23
24
# File 'lib/ya_kansuji/formatter/judic_v.rb', line 7

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

  ret = ''
  head = true
  (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 head
      ret << i4.to_s + unit4
    else
      ret << ('%04d' % i4) + unit4
    end
    head = false
  end
  ret.tr('0-9', '〇一二三四五六七八九')
end