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 = {}, &blk) ⇒ Verb
constructor
A new instance of Verb.
Constructor Details
#initialize(infinitive, options = {}, &blk) ⇒ Verb
Returns a new instance of Verb.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/verbs/verb.rb', line 5 def initialize(infinitive, = {}, &blk) @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.
3 4 5 |
# File 'lib/verbs/verb.rb', line 3 def infinitive @infinitive end |
#past_participle ⇒ Object (readonly)
Returns the value of attribute past_participle.
3 4 5 |
# File 'lib/verbs/verb.rb', line 3 def past_participle @past_participle end |
#preterite ⇒ Object (readonly)
Returns the value of attribute preterite.
3 4 5 |
# File 'lib/verbs/verb.rb', line 3 def preterite @preterite end |
Instance Method Details
#[](options = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/verbs/verb.rb', line 33 def []( = {}) tense, person, plurality, derivative, mood = [:tense], [:person], [:plurality], [:derivative], [: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 |
#form(word, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/verbs/verb.rb', line 16 def form(word, = {}) raise ArgumentError, 'Irregular verb specifications must identify tense and must identify either derivative, mood, or person and plurality' unless [:tense] and ([:derivative] or [:mood] or ([:person] and [:plurality])) 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 |