Sha256: 1648e87a9439a60bc9ff1835ba84a3ad71c6194c6b9a97b0423e905938082504
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
module HaikuGadget class WordType attr_reader :base_symbol, :can_be_plural, :add_s_target 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 def self.custom(custom_words = []) WordType.new :custom, false, nil, custom_words end # translates the base symbol type into a _singular or _plural one if necessary # for doing dictionary lookups 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 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 def words?(syllables, plurality = :none) if base_symbol == :custom !get_word(syllables, plurality).nil? else Dictionary.words? self, syllables, plurality end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
haiku_gadget-1.0.12 | lib/haiku_gadget/word_type.rb |