Sha256: 58665c5bf5d52b66f9687c018402fb36e1ade4ff3ad0969be570d497ef7adbdf

Contents?: true

Size: 979 Bytes

Versions: 7

Compression:

Stored size: 979 Bytes

Contents

begin
  require 'anthy'
  Anthy.set_personality("")
rescue LoadError
end

require 'rabbit/utils'

module Rabbit
  module Parser
    module Ext
      module Anthy
        include Element
        include GetText

        module_function
        def available?
          defined?(::Anthy)
        end

        def hiragana_to_kanji(text)
          context = ::Anthy::Context.new
          context.encoding = ::Anthy::EUC_JP_ENCODING
          converted_text = ''
          text.split(/(\s+)/m).each do |sentence|
            if /\A\s+\z/m =~ sentence
              converted_text << sentence
              next
            end
            context.reset
            context.string = Converter.to_eucjp_from_utf8(sentence)
            context.stat.nr_segment.times do |i|
              segment = context.segment(i, 0)
              converted_text << Converter.to_utf8_from_eucjp(segment)
            end
          end

          converted_text
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rabbit-0.9.3 lib/rabbit/parser/ext/anthy.rb
rabbit-0.9.2 lib/rabbit/parser/ext/anthy.rb
rabbit-0.9.1 lib/rabbit/parser/ext/anthy.rb
rabbit-0.9.0 lib/rabbit/parser/ext/anthy.rb
rabbit-0.6.4 lib/rabbit/parser/ext/anthy.rb
rabbit-0.6.3 lib/rabbit/parser/ext/anthy.rb
rabbit-0.6.2 lib/rabbit/parser/ext/anthy.rb