Module: Verbs::Conjugator

Extended by:
Conjugator
Included in:
Conjugator
Defined in:
lib/verbs/conjugator.rb

Defined Under Namespace

Classes: Conjugations

Instance Method Summary collapse

Instance Method Details

#conjugate(infinitive, options = {}) ⇒ Object

Using options given, determine the conjugation and the subject Return the subject, if there is one, and the proper conjugation Params:

  • infinitive, the given verb

  • options, the list of parameters to alter the conjugation



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/verbs/conjugator.rb', line 79

def conjugate(infinitive, options = {})
  infinitive = infinitive.dup if infinitive.is_a?(String)

  # set all options according to parameter, or the default
  tense = options[:tense] ||         :present    # present, past, future
  person = options[:person] ||       :third      # first, second, third
  plurality = options[:plurality] || :singular   # singular, plural
  diathesis = options[:diathesis] || :active     # active, passive
  mood = options[:mood] ||           :indicative # imperative, subjunctive
  aspect = options[:aspect] ||       default_aspect(options) # perfective, habitual, progressive, perfect, prospective

  check_for_improper_constructions(infinitive, tense, person, mood, diathesis) # find incompatabilities
  form = form_for(tense, aspect, diathesis)                                    # find form array based on tense and aspect

  # map form array to conjugation array, applying infinitive and options to the array
  conjugation = form.map { |e| resolve e, infinitive, tense, person, plurality, mood }.join(' ').strip

  if options[:subject]                   # When options includes a subject,
    actor = options.delete(:subject)     # remove from options and make subject humanized
    actor = subject(options).humanize if actor.is_a?(TrueClass)
  end

  "#{actor} #{conjugation}".strip
end

#conjugationsObject

Runs a block of code if given in a class instance else only class instance is created



66
67
68
69
70
71
72
# File 'lib/verbs/conjugator.rb', line 66

def conjugations
  if block_given?
    yield Conjugations.instance
  else
    Conjugations.instance
  end
end

#subject(options) ⇒ Object

Finds the pronoun associated with the subject for the conjugation Returns the pronoun Params:

  • options, list of options given to determine conjugation



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/verbs/conjugator.rb', line 108

def subject(options)
  case [options[:person], options[:plurality]]
  when %i[first singular]
    'I'
  when %i[first plural]
    'we'
  when %i[second singular], %i[second plural]
    'you'
  when %i[third singular]
    'he'
  when %i[third plural]
    'they'
  end
end