Module: YaKansuji::Formatter::Lawyer

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

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

  ret = ''
  (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
      ret << "1#{unit4}"
      next
    end

    ret << (i4 >= 1000 ? "#{i4.to_s[0]},#{i4.to_s[1..-1]}" : i4.to_s) + unit4
  end
  ret
end