class Katsuyou::DeterminesType

Public Class Methods

type_for(code) click to toggle source
# File lib/katsuyou/determines_type.rb, line 43
def self.type_for(code)
  CONJUGATION_TYPES.find { |type| type.code == code }
end

Public Instance Methods

call(text:, type:) click to toggle source
# File lib/katsuyou/determines_type.rb, line 47
def call(text:, type:)
  type = type.to_s
  if type == "ichidan_verb"
    type_for("v1")
  elsif type == "godan_verb"
    guess_godan_type(text)
  elsif type == "kuru_verb"
    type_for("vk")
  elsif type == "suru_verb"
    guess_suru_type(text)
  else
    type_for(type)
  end
end

Private Instance Methods

guess_godan_type(text) click to toggle source
# File lib/katsuyou/determines_type.rb, line 64
def guess_godan_type(text)
  if text.end_with?("行く", "いく")
    type_for("v5k-s")
  elsif text.end_with?("有る", "ある")
    type_for("v5r-i")
  else
    case text[-1]
    when "ぶ" then type_for("v5b")
    when "ぐ" then type_for("v5g")
    when "く" then type_for("v5k")
    when "む" then type_for("v5m")
    when "ぬ" then type_for("v5n")
    when "る" then type_for("v5r")
    when "す" then type_for("v5s")
    when "つ" then type_for("v5t")
    when "う" then type_for("v5u")
    end
  end
end
guess_suru_type(text) click to toggle source
# File lib/katsuyou/determines_type.rb, line 84
def guess_suru_type(text)
  if text.end_with?("為る", "する")
    type_for("vs-i")
  else
    type_for("vs")
  end
end
type_for(code) click to toggle source
# File lib/katsuyou/determines_type.rb, line 92
def type_for(code)
  self.class.type_for(code)
end