Class: Datte::TextConverter
- Inherits:
-
Object
- Object
- Datte::TextConverter
- 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
-
#initialize(options = {}) ⇒ TextConverter
constructor
A new instance of TextConverter.
- #kan_num(body) ⇒ Object
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 = end |
Instance Method Details
#kan_num(body) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# 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 p kan, num body.gsub!(kan, num.to_s) end body end |