Class: Verbs::Verb
- Inherits:
-
Object
- Object
- Verbs::Verb
- Defined in:
- lib/verbs/verb.rb
Instance Attribute Summary collapse
-
#infinitive ⇒ Object
readonly
Returns the value of attribute infinitive.
-
#past_participle ⇒ Object
readonly
Returns the value of attribute past_participle.
-
#preterite ⇒ Object
readonly
Returns the value of attribute preterite.
Instance Method Summary collapse
- #[](options = {}) ⇒ Object
- #form(word, options = {}) ⇒ Object
-
#initialize(infinitive, options = {}) ⇒ Verb
constructor
A new instance of Verb.
Constructor Details
#initialize(infinitive, options = {}) ⇒ Verb
Returns a new instance of Verb.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/verbs/verb.rb', line 7 def initialize(infinitive, = {}) @infinitive = infinitive @forms = {} if block_given? yield self else @preterite = [:preterite] @past_participle = [:past_participle] end end |
Instance Attribute Details
#infinitive ⇒ Object (readonly)
Returns the value of attribute infinitive.
5 6 7 |
# File 'lib/verbs/verb.rb', line 5 def infinitive @infinitive end |
#past_participle ⇒ Object (readonly)
Returns the value of attribute past_participle.
5 6 7 |
# File 'lib/verbs/verb.rb', line 5 def past_participle @past_participle end |
#preterite ⇒ Object (readonly)
Returns the value of attribute preterite.
5 6 7 |
# File 'lib/verbs/verb.rb', line 5 def preterite @preterite end |
Instance Method Details
#[](options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/verbs/verb.rb', line 38 def []( = {}) tense = [:tense] person = [:person] plurality = [:plurality] derivative = [:derivative] mood = [:mood] if tense && person && plurality && mood @forms[tense].try(:[], mood) || @forms[tense].try(:[], person).try(:[], plurality) elsif tense && derivative @forms[tense].try(:[], derivative) end end |
#form(word, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/verbs/verb.rb', line 18 def form(word, = {}) unless [:tense] && ([:derivative] || [:mood] || ([:person] && [:plurality])) raise ArgumentError, 'Irregular verb specifications must identify tense and must identify either derivative, mood, or person and plurality' end tense = [:tense] @forms[:present] ||= {} @forms[:past] ||= {} if (derivative = [:derivative]) @forms[tense][derivative] = word elsif (mood = [:mood]) @forms[tense][mood] = word elsif (person = [:person]) @forms[tense][person] ||= {} @forms[tense][person][[:plurality]] = word end end |