Class: HaikuGadget::WordType
- Inherits:
-
Object
- Object
- HaikuGadget::WordType
- Defined in:
- lib/haiku_gadget/word_type.rb
Instance Attribute Summary collapse
-
#add_s_target ⇒ Object
readonly
Returns the value of attribute add_s_target.
-
#base_symbol ⇒ Object
readonly
Returns the value of attribute base_symbol.
-
#can_be_plural ⇒ Object
readonly
Returns the value of attribute can_be_plural.
Class Method Summary collapse
Instance Method Summary collapse
-
#dict_symbol(plurality) ⇒ Object
translates the base symbol type into a _singular or _plural one if necessary for doing dictionary lookups.
- #get_word(syllables, plurality = :none) ⇒ Object
-
#initialize(base_symbol, can_be_plural = false, add_s_target = nil, custom_words = []) ⇒ WordType
constructor
A new instance of WordType.
- #words?(syllables, plurality = :none) ⇒ Boolean
Constructor Details
#initialize(base_symbol, can_be_plural = false, add_s_target = nil, custom_words = []) ⇒ WordType
Returns a new instance of WordType.
7 8 9 10 11 12 |
# File 'lib/haiku_gadget/word_type.rb', line 7 def initialize(base_symbol, can_be_plural = false, add_s_target = nil, custom_words = []) @base_symbol = base_symbol @can_be_plural = can_be_plural @add_s_target = add_s_target @custom_words = custom_words end |
Instance Attribute Details
#add_s_target ⇒ Object (readonly)
Returns the value of attribute add_s_target.
5 6 7 |
# File 'lib/haiku_gadget/word_type.rb', line 5 def add_s_target @add_s_target end |
#base_symbol ⇒ Object (readonly)
Returns the value of attribute base_symbol.
5 6 7 |
# File 'lib/haiku_gadget/word_type.rb', line 5 def base_symbol @base_symbol end |
#can_be_plural ⇒ Object (readonly)
Returns the value of attribute can_be_plural.
5 6 7 |
# File 'lib/haiku_gadget/word_type.rb', line 5 def can_be_plural @can_be_plural end |
Class Method Details
.custom(custom_words = []) ⇒ Object
14 15 16 |
# File 'lib/haiku_gadget/word_type.rb', line 14 def self.custom(custom_words = []) WordType.new :custom, false, nil, custom_words end |
Instance Method Details
#dict_symbol(plurality) ⇒ Object
translates the base symbol type into a _singular or _plural one if necessary for doing dictionary lookups
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/haiku_gadget/word_type.rb', line 20 def dict_symbol(plurality) # do not allow plurality of :none for a word that has plurality # this is a redundant error check and should not happen plurality = [:singular, :plural].sample if @can_be_plural && plurality == :none if plurality == :common || (@can_be_plural && [:singular, :plural].include?(plurality)) # word can be plural or is from the common set "#{@base_symbol.to_s}_#{plurality.to_s}".to_sym else # word type is not relevent to plurality @base_symbol end end |
#get_word(syllables, plurality = :none) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/haiku_gadget/word_type.rb', line 34 def get_word(syllables, plurality = :none) if base_symbol == :custom if syllables > 0 Dictionary.word_from_array @custom_words, syllables else nil end else Dictionary.get_word self, syllables, plurality end end |
#words?(syllables, plurality = :none) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/haiku_gadget/word_type.rb', line 46 def words?(syllables, plurality = :none) if base_symbol == :custom !get_word(syllables, plurality).nil? else Dictionary.words? self, syllables, plurality end end |