class Rubyfuri::ResponseParsers::Base

Public Class Methods

new(original, xml) click to toggle source
# File lib/rubyfuri/response_parsers/base.rb, line 6
def initialize(original, xml)
  @original = original
  @furigana_doc = Nokogiri::HTML(xml)
  @furiganas = []
  @surfaces = []
  build_furiganas_and_surfaces
end

Public Instance Methods

ruby() click to toggle source
# File lib/rubyfuri/response_parsers/base.rb, line 14
def ruby
  raise NotImplementedError
end

Private Instance Methods

build_furiganas_and_surfaces() click to toggle source
# File lib/rubyfuri/response_parsers/base.rb, line 20
def build_furiganas_and_surfaces
  @furigana_doc.xpath('//word').each_with_index do |word|
    surface = word.xpath('surface').text
    furigana = word.xpath('furigana').text

    if !(furigana.empty?)
      @furiganas << furigana
    else
      # 英数のときは surface にその文字・数字が入ってる
      # スペースのときは surface が empty となっている
      if !(surface.empty?)
        @furiganas << surface
      else
        @furiganas << ' '
      end
    end

    @surfaces << surface
  end
end