class Declension::Languages::Lv

Constants

CASES
EXCEPTIONAL_MALE_WORDS
GENDERS

Attributes

declension[RW]
ending[RW]
exception[RW]
gender[RW]
word_base[RW]

Public Instance Methods

analyze_female_gender_word() click to toggle source
# File lib/declension/languages/lv.rb, line 57
def analyze_female_gender_word
  self.ending = word[-1, 1]

  if ending == 'a'
    self.declension = 4
  elsif ending == 'e'
    self.declension = 5
  elsif ending == 's'
    self.declension = 6
  end
end
analyze_male_gender_word() click to toggle source
# File lib/declension/languages/lv.rb, line 27
def analyze_male_gender_word
  short_ending = word[-1, 1]
  long_ending = word[-2, 2]

  if EXCEPTIONAL_MALE_WORDS.include? word
    self.exception = true
    self.declension = 2
    self.ending = 's'
  elsif word == 'ļaudis'
    self.exception = true
    self.declension = 6
    self.ending = 'is'
  elsif long_ending == 'is'
    self.declension = 2
    self.ending = long_ending
  elsif long_ending == 'us'
    self.declension = 3
    self.ending = long_ending
  elsif short_ending == 's' || short_ending == 'š'
    self.declension = 1
    self.ending = short_ending
  elsif short_ending == 'a'
    self.declension = 4
    self.ending = short_ending
  elsif short_ending == 'e'
    self.declension = 5
    self.ending = short_ending
  end
end
analyze_word() click to toggle source
# File lib/declension/languages/lv.rb, line 15
def analyze_word
  if gender == GENDER_MALE
    analyze_male_gender_word
  elsif gender == GENDER_FEMALE
    analyze_female_gender_word
  else
    raise ArgumentError, "No valid gender specified"
  end

  self.word_base = word[0..-(ending.length + 1)] if declension
end
assign_options(options) click to toggle source
# File lib/declension/languages/lv.rb, line 69
def assign_options(options)
  self.gender = Array(options[:as]).map(&:to_sym).find{|option| GENDERS.include? option }
end
fifth_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 172
def fifth_declension(grammar_case, options = {})
  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    word_base + 'es'
  when DATIVE_CASE
    word_base + (gender == GENDER_MALE ? 'em' : 'ei')
  when ACCUSATIVE_CASE
    word_base + 'i'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'i'
  when LOCATIVE_CASE
    word_base + 'ē'
  when VOCATIVE_CASE
    word_base + 'e!'
  end
end
first_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 94
def first_declension(grammar_case, options = {})
  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    word_base + 'a'
  when DATIVE_CASE
    word_base + 'am'
  when ACCUSATIVE_CASE
    word_base + 'u'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'u'
  when LOCATIVE_CASE
    word_base + 'ā'
  when VOCATIVE_CASE
    word_base + (ending == 's' ? 's' : 'š') + "!"
  end
end
forth_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 153
def forth_declension(grammar_case, options = {})
  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    word_base + 'as'
  when DATIVE_CASE
    word_base + (gender == GENDER_MALE ? 'am' : 'ai')
  when ACCUSATIVE_CASE
    word_base + 'u'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'u'
  when LOCATIVE_CASE
    word_base + 'ā'
  when VOCATIVE_CASE
    word_base + 'a!'
  end
end
inflect(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 73
def inflect(grammar_case, options = {})
  assign_options(options)
  analyze_word

  if declension == 1
    first_declension(grammar_case, options = {})
  elsif declension == 2
    second_declension(grammar_case, options = {})
  elsif declension == 3
    third_declension(grammar_case, options = {})
  elsif declension == 4
    forth_declension(grammar_case, options = {})
  elsif declension == 5
    fifth_declension(grammar_case, options = {})
  elsif declension == 6
    sixth_declension(grammar_case, options = {})
  else
    word
  end
end
second_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 113
def second_declension(grammar_case, options = {})
  inflected_base = exception ? word_base : Lv::Inflections.inflect(word, word_base, declension)

  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    inflected_base + (ending == 'is' ? 'a' : 's')
  when DATIVE_CASE
    word_base + 'im'
  when ACCUSATIVE_CASE
    word_base + 'i'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'i'
  when LOCATIVE_CASE
    word_base + 'ī'
  when VOCATIVE_CASE
    word_base + (ending == 'is' ? 'i!' : '!')
  end
end
sixth_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 191
def sixth_declension(grammar_case, options = {})
  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    word_base + 's'
  when DATIVE_CASE
    word_base + 'ij'
  when ACCUSATIVE_CASE
    word_base + 'i'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'i'
  when LOCATIVE_CASE
    word_base + 'ī'
  when VOCATIVE_CASE
    word_base + 's!'
  end
end
third_declension(grammar_case, options = {}) click to toggle source
# File lib/declension/languages/lv.rb, line 134
def third_declension(grammar_case, options = {})
  case grammar_case
  when NOMINATIVE_CASE
    word_base + ending
  when GENITIVE_CASE
    word_base + 'us'
  when DATIVE_CASE
    word_base + 'um'
  when ACCUSATIVE_CASE
    word_base + 'u'
  when INSTRUMENTAL_CASE
    'ar ' + word_base + 'u'
  when LOCATIVE_CASE
    word_base + 'ū'
  when VOCATIVE_CASE
    word_base + '(us|u)!'
  end
end