Module: Conjugue
- Defined in:
- lib/conjugue.rb,
lib/conjugue/verb_database.rb
Defined Under Namespace
Modules: VerbDatabase
Class Method Summary collapse
Class Method Details
.verbo(name, time, person, plural = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 56 |
# File 'lib/conjugue.rb', line 5 def self.verbo(name, time, person, plural = false) unless name =~ /r$/ unless name =~ /[aeiou]$/ name += 'a' end name += 'r' end time = VerbDatabase::TIMES[time] plural = false if plural == :s person -= 1 person += 3 if plural paradigm = (VerbDatabase.find_by_verb(name) or VerbDatabase.find_by_paradigm(name) or VerbDatabase.find_by_sufix(name)) # Try finding paradigm by sufix unless (paradigm[:conjugations][time] rescue nil) puts 'time not found' paradigm = VerbDatabase.find_by_sufix(name) # Try shortening the sufix unless (paradigm[:conjugations][time] rescue nil) if (paradigm[:sufix] rescue nil) while (sufix = paradigm[:sufix].to_s[1..-1]).size > 1 paradigm = VerbDatabase.find_by_sufix(sufix) rescue nil break if paradigm end end end end if paradigm begin sufix = (paradigm[:sufix].to_s.empty? ? paradigm[:name] : paradigm[:sufix]) conjugate = paradigm[:conjugations][time][person] radical_paradigm = paradigm[:name].gsub(Regexp.new(sufix+'$'), '') sufix_conjugate = conjugate.gsub(Regexp.new('^'+radical_paradigm), '') radical_verb = name.gsub(Regexp.new(sufix+'$'), '') conjugate = radical_verb + sufix_conjugate rescue nil end else conjugate = name end ret = "#{VerbDatabase::PRONOUNS[person]} #{conjugate}" ret.encode('UTF-8') end |