class Declension::Languages::Lv::Inflections

Constants

INFLECTIONS

Attributes

declension[RW]
word[RW]
word_base[RW]

Public Class Methods

inflect(word, word_base, declension) click to toggle source
# File lib/declension/languages/lv/inflections.rb, line 22
def self.inflect(word, word_base, declension)
  inflection = new(word, word_base, declension)
  if inflection.exceptionable?
    word_base
  else
    inflection.inflect
  end
end
new(word, word_base, declension) click to toggle source
# File lib/declension/languages/lv/inflections.rb, line 31
def initialize(word, word_base, declension)
  self.word = word
  self.word_base = word_base
  self.declension = declension
end

Public Instance Methods

exceptionable?() click to toggle source
# File lib/declension/languages/lv/inflections.rb, line 48
def exceptionable?
  if declension == 2
      word == 'tētis' ||
      word == 'viesis' ||
      word[-5, 5] == 'astis' ||
      word[-3, 3] == 'jis' ||
      word[-3, 3] == 'ķis' ||
      word[-3, 3] == 'ģis' ||
      word[-3, 3] == 'ris' ||
      word[-6, 6] == 'skatis'
  end
end
inflect() click to toggle source
# File lib/declension/languages/lv/inflections.rb, line 37
def inflect
  [3, 2, 1].each do|iteration|
    ending = word_base[-iteration, iteration]
    INFLECTIONS.fetch(declension, {}).fetch(iteration, {}).each_pair do|key, value|
      return (word_base[0..-(iteration + 1)] + value) if key == ending
    end
  end

  word_base
end