Class: Declension::Languages::Lv

Inherits:
Base
  • Object
show all
Defined in:
lib/declension/languages/lv.rb

Defined Under Namespace

Classes: Inflections

Constant Summary collapse

GENDERS =
[
  GENDER_MALE = :male,
  GENDER_FEMALE = :female
]
EXCEPTIONAL_MALE_WORDS =
%w(mēness akmens asmens rudens ūdens zibens suns sāls)
CASES =
[NOMINATIVE_CASE, GENITIVE_CASE, DATIVE_CASE, ACCUSATIVE_CASE, INSTRUMENTAL_CASE, LOCATIVE_CASE, VOCATIVE_CASE]

Instance Attribute Summary collapse

Attributes inherited from Base

#word

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Declension::Languages::Base

Instance Attribute Details

#declensionObject

Returns the value of attribute declension.



13
14
15
# File 'lib/declension/languages/lv.rb', line 13

def declension
  @declension
end

#endingObject

Returns the value of attribute ending.



13
14
15
# File 'lib/declension/languages/lv.rb', line 13

def ending
  @ending
end

#exceptionObject

Returns the value of attribute exception.



13
14
15
# File 'lib/declension/languages/lv.rb', line 13

def exception
  @exception
end

#genderObject

Returns the value of attribute gender.



13
14
15
# File 'lib/declension/languages/lv.rb', line 13

def gender
  @gender
end

#word_baseObject

Returns the value of attribute word_base.



13
14
15
# File 'lib/declension/languages/lv.rb', line 13

def word_base
  @word_base
end

Instance Method Details

#analyze_female_gender_wordObject



57
58
59
60
61
62
63
64
65
66
67
# 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_wordObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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_wordObject



15
16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object



69
70
71
# 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 = {}) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# 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 = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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 = {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# 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 = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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 = {}) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 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 = {}) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# 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 = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# 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