lib/haiku_gadget/dictionary.rb in haiku_gadget-1.0.11 vs lib/haiku_gadget/dictionary.rb in haiku_gadget-1.0.12

- old
+ new

@@ -142,25 +142,30 @@ # validate syllables input return nil unless syllables.is_a?(Fixnum) && syllables > 0 dict_symbol = word_type.dict_symbol plurality - if @@dict[dict_symbol] && @@dict[dict_symbol][syllables - 1] - word_or_array = @@dict[dict_symbol][syllables - 1].sample + Dictionary.word_from_array @@dict[dict_symbol], syllables + + end + + def self.words?(word_type, syllables, plurality = :none) + !Dictionary.get_word(word_type, syllables, plurality).nil? + end + + def self.word_from_array(array, syllables) + if array && array[syllables - 1] + word_or_array = array[syllables - 1].sample while word_or_array.is_a? Array # this item contains a nested list of items (to limit chances of nested item being selected) # sample from nested array and try again to find a word ("leaf node") word_or_array = word_or_array.sample end # current item is a word and not a nested list, return it word_or_array else nil end - end - - def self.words?(word_type, syllables, plurality = :none) - !Dictionary.get_word(word_type, syllables, plurality).nil? end end end \ No newline at end of file