Sha256: 245e3da6582642100fdbd34c4f987335f3391b2ed52fe579757480bfb9f1f22e

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

Stored size: 1.43 KB

Contents

module Verbs
  class Verb
    attr_reader :infinitive, :preterite, :past_participle
    
    def initialize(infinitive, options = {}, &blk)
      @infinitive = infinitive
      @forms = {}
      if block_given?
        yield self
      else
        @preterite = options[:preterite]
        @past_participle = options[:past_participle]
      end
    end
    
    def form(word, options = {})
      raise ArgumentError, 'Irregular verb specifications must identify tense and must identify either derivative, mood, or person and plurality' unless options[:tense] and (options[:derivative] or options[:mood] or (options[:person] and options[:plurality]))
      
      tense = options[:tense]

      @forms[:present] ||= {}
      @forms[:past] ||= {}
      if derivative = options[:derivative]
        @forms[tense][derivative] = word
      elsif mood = options[:mood]
        @forms[tense][mood] = word
      elsif person = options[:person]
        @forms[tense][person] ||= {}
        @forms[tense][person][options[:plurality]] = word
      end
    end
    
    def [](options = {})
      tense, person, plurality, derivative, mood = options[:tense], options[:person], options[:plurality], options[:derivative], options[:mood]
      if tense and person and plurality and mood
        @forms[tense].try(:[], mood) || @forms[tense].try(:[], person).try(:[], plurality)
      elsif tense and derivative
        @forms[tense].try(:[], derivative)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
verbs-3.0.0 lib/verbs/verb.rb
verbs-2.3.1 lib/verbs/verb.rb
verbs-2.3.0 lib/verbs/verb.rb
verbs-2.2.1 lib/verbs/verb.rb
verbs-2.2.0 lib/verbs/verb.rb
verbs-2.1.4 lib/verbs/verb.rb
verbs-2.1.3 lib/verbs/verb.rb
verbs-2.1.2 lib/verbs/verb.rb
verbs-2.1.1 lib/verbs/verb.rb
verbs-2.1.0 lib/verbs/verb.rb