Class: Datte::TextConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/datte/text_converter.rb

Constant Summary collapse

KANNUM_ALL =
['', '', '', '', '', '', '', '', '', '', '', '']
KANNUM_1_9 =
{ ''=>1, ''=>1, ''=>2, ''=>3, ''=>4, ''=>5, ''=>6, ''=>7, ''=>8, ''=>9 }
KANNUM_10 =
{''=>1000, ''=>100, ''=>10, ''=>1 }

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TextConverter

Returns a new instance of TextConverter.



8
9
10
# File 'lib/datte/text_converter.rb', line 8

def initialize(options = {})
  @options = options
end

Instance Method Details

#kan_num(body) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/datte/text_converter.rb', line 12

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