Class: Declension::Languages::Lv::Inflections
- Inherits:
-
Object
- Object
- Declension::Languages::Lv::Inflections
- Defined in:
- lib/declension/languages/lv/inflections.rb
Constant Summary collapse
- INFLECTIONS =
{ 2 => { 1 => {'b' => 'bj', 'm' => 'mj', 'p' => 'pj', 'v' => 'vj', 't' => 'š', 'd' => 'ž', 'c' => 'č', 's' => 'š', 'z' => 'ž', 'n' => 'ņ', 'l' => 'ļ'}, 2 => {'dz' => 'dž', 'sn' => 'šņ', 'zn' => 'žņ', 'sl' => 'šļ', 'zl' => 'žļ', 'ln' => 'ļņ'} }, 5 => { 1 => {'b' => 'bj', 'm' => 'mj', 'p' => 'pj', 'v' => 'vj', 'c' => 'č', 't' => 'š', 'd' => 'ž', 's' => 'š', 'z' => 'ž', 'n' => 'ņ', 'l' => 'ļ'}, 2 => {'sn' => 'šņ', 'zn' => 'žņ', 'dz' => 'dž'}, 3 => {'kst' => 'kp'} }, 6 => { 1 => {'v' => 'vj', 't' => 'š', 'd' => 'ž', 's' => 'š', 'z' => 'ž', 'n' => 'ņ', 'l' => 'ļ'}, 2 => {'sn' => 'šņ', 'st' => 'š'} } }
Instance Attribute Summary collapse
-
#declension ⇒ Object
Returns the value of attribute declension.
-
#word ⇒ Object
Returns the value of attribute word.
-
#word_base ⇒ Object
Returns the value of attribute word_base.
Class Method Summary collapse
Instance Method Summary collapse
- #exceptionable? ⇒ Boolean
- #inflect ⇒ Object
-
#initialize(word, word_base, declension) ⇒ Inflections
constructor
A new instance of Inflections.
Constructor Details
#initialize(word, word_base, declension) ⇒ Inflections
Returns a new instance of Inflections.
31 32 33 34 35 |
# 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 |
Instance Attribute Details
#declension ⇒ Object
Returns the value of attribute declension.
4 5 6 |
# File 'lib/declension/languages/lv/inflections.rb', line 4 def declension @declension end |
#word ⇒ Object
Returns the value of attribute word.
4 5 6 |
# File 'lib/declension/languages/lv/inflections.rb', line 4 def word @word end |
#word_base ⇒ Object
Returns the value of attribute word_base.
4 5 6 |
# File 'lib/declension/languages/lv/inflections.rb', line 4 def word_base @word_base end |
Class Method Details
.inflect(word, word_base, declension) ⇒ Object
22 23 24 25 26 27 28 29 |
# 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 |
Instance Method Details
#exceptionable? ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# 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 |