class Katsuyou::ConjugatesVerb

Public Class Methods

new() click to toggle source
# File lib/katsuyou/conjugates_verb.rb, line 7
def initialize
  @determines_type = DeterminesType.new
  @zips_endings = ZipsEndings.new
end

Public Instance Methods

call(verb, type:) click to toggle source
# File lib/katsuyou/conjugates_verb.rb, line 12
def call(verb, type:)
  conjugation_type = @determines_type.call(text: verb, type: type)
  ensure_valid_conjugation_type!(type, conjugation_type)

  VerbConjugation.new({
    conjugation_type: conjugation_type
  }.merge(@zips_endings.call(verb, conjugation_type)))
end

Private Instance Methods

ensure_valid_conjugation_type!(user_type, conjugation_type) click to toggle source
# File lib/katsuyou/conjugates_verb.rb, line 23
def ensure_valid_conjugation_type!(user_type, conjugation_type)
  if conjugation_type.nil?
    raise InvalidConjugationTypeError.new(
      "We don't know about conjugation type '#{user_type}'"
    )
  elsif !conjugation_type.supported
    raise UnsupportedConjugationTypeError.new(
      "Conjugation type '#{conjugation_type.code}' is not yet supported"
    )
  end
end