Class: HaikuGadget::WordTemplate
- Inherits:
-
Object
- Object
- HaikuGadget::WordTemplate
- Defined in:
- lib/haiku_gadget/word_template.rb
Instance Attribute Summary collapse
-
#obj_num ⇒ Object
readonly
Returns the value of attribute obj_num.
-
#plurality ⇒ Object
Returns the value of attribute plurality.
-
#syllables ⇒ Object
Returns the value of attribute syllables.
-
#word_type ⇒ Object
readonly
Returns the value of attribute word_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base_symbol_or_word_type, syllables = 0, plurality = :none, obj_num = 0) ⇒ WordTemplate
constructor
A new instance of WordTemplate.
Constructor Details
#initialize(base_symbol_or_word_type, syllables = 0, plurality = :none, obj_num = 0) ⇒ WordTemplate
Returns a new instance of WordTemplate.
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 |
# File 'lib/haiku_gadget/word_template.rb', line 10 def initialize(base_symbol_or_word_type, syllables = 0, plurality = :none, obj_num = 0) if base_symbol_or_word_type.is_a? HaikuGadget::WordType # use provided (custom) WordType word_type = base_symbol_or_word_type else # look up word type based on symbol word_type = Dictionary::WORD_TYPES[base_symbol_or_word_type] end fail "unknown word type '#{base_symbol_or_word_type.to_s}'" unless word_type # check if template plurality needs to be set or changed if word_type.can_be_plural plurality = :any if plurality == :none else plurality = :none end @word_type = word_type @syllables = syllables @plurality = plurality @obj_num = obj_num end |
Instance Attribute Details
#obj_num ⇒ Object (readonly)
Returns the value of attribute obj_num.
7 8 9 |
# File 'lib/haiku_gadget/word_template.rb', line 7 def obj_num @obj_num end |
#plurality ⇒ Object
Returns the value of attribute plurality.
8 9 10 |
# File 'lib/haiku_gadget/word_template.rb', line 8 def plurality @plurality end |
#syllables ⇒ Object
Returns the value of attribute syllables.
8 9 10 |
# File 'lib/haiku_gadget/word_template.rb', line 8 def syllables @syllables end |
#word_type ⇒ Object (readonly)
Returns the value of attribute word_type.
7 8 9 |
# File 'lib/haiku_gadget/word_template.rb', line 7 def word_type @word_type end |
Class Method Details
.custom(word_list, syllables) ⇒ Object
36 37 38 39 40 |
# File 'lib/haiku_gadget/word_template.rb', line 36 def self.custom(word_list, syllables) WordTemplate.new WordType.custom(word_list), syllables end |