Module: YaKansuji::Formatter::Lawyer
- Defined in:
- lib/ya_kansuji/formatter/lawyer.rb
Overview
Formatter for Jpanese lawyer style kansuji
Class Method Summary collapse
Class Method Details
.call(num, _options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ya_kansuji/formatter/lawyer.rb', line 10 def call(num, = {}) int, frac = Formatter.split_fraction(num) frac.empty? ? frac_part = nil : frac_part = ".#{frac.join}" return frac_part ? "0#{frac_part}" : '0' if int.zero? ret = +'' chunks = Formatter.split_by_unit4(int) (chunks.size - 1).downto(0) do |idx4| i4 = chunks[idx4] next if i4.zero? && !(idx4.zero? && frac_part) unit4 = Formatter::UNIT4_UNITS[idx4] 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 << frac_part if frac_part ret end |