Sha256: 80071a94ad32c6095de87a8b1f9b332012e5275e994fdcbb87177d5b2108e2b3

Contents?: true

Size: 697 Bytes

Versions: 1

Compression:

Stored size: 697 Bytes

Contents

class LetterPressIsNotAsGoodAsBoggle
  class WordList
    class Searcher
      NoPath = Class.new StandardError

      attr_reader :word_list

      def initialize(word_list)
        @node = word_list.root
      end

      def down?(char)
        @node.child? char
      end

      def down(char)
        raise NoPath, "No path #{@node.to_s << char}." unless down? char
        @node = @node.child char
      end

      def current
        @node.to_s
      end

      def up
        new_node = @node.parent
        raise NoPath, "Can't go up from root." unless new_node
        @node = new_node
      end

      # rename to on_word?
      def word?
        @node.word?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
letter_press_is_not_as_good_as_boggle-1.0.0 lib/letter_press_is_not_as_good_as_boggle/word_list/searcher.rb