Sha256: 7c28fbaaa3d2c5bb294f78c68dc5c911618080a4441234f08685c46b0be90e49
Contents?: true
Size: 691 Bytes
Versions: 3
Compression:
Stored size: 691 Bytes
Contents
module Datte class TextConverter KANNUM_ALL = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '百', '千'] KANNUM_1_9 = { ''=>1, '一'=>1, '二'=>2, '三'=>3, '四'=>4, '五'=>5, '六'=>6, '七'=>7, '八'=>8, '九'=>9 } KANNUM_10 = {'千'=>1000, '百'=>100, '十'=>10, ''=>1 } def initialize(options = {}) @options = options end def kan_num(body) body.scan(/[#{KANNUM_ALL.join('')}]+/).each do |kan| num = kan.scan(/([^千百十]*)([千百十]?)/).inject(-1) do |num, (_1_9, unit)| num + KANNUM_1_9[_1_9] * KANNUM_10[unit] end body.gsub!(kan, num.to_s) end body end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
datte-0.6.2 | lib/datte/text_converter.rb |
datte-0.6.1 | lib/datte/text_converter.rb |
datte-0.6.0 | lib/datte/text_converter.rb |