Sha256: dd431285b2ff2b566aada3864c19dc532e2a3f3432eeed88b0eb5e6659654b33

Contents?: true

Size: 802 Bytes

Versions: 2

Compression:

Stored size: 802 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 has_child?(char)
        @node.child? char
      end

      def down_to(char)
        raise NoPath, "No path #{@node.to_s << char}." unless has_child? char
        @node = @node.child char
        if block_given?
          begin
            yield
          ensure
            up
          end
        end
      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

      def on_word?
        @node.word?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
letter_press_is_not_as_good_as_boggle-1.0.2 lib/letter_press_is_not_as_good_as_boggle/word_list/searcher.rb
letter_press_is_not_as_good_as_boggle-1.0.1 lib/letter_press_is_not_as_good_as_boggle/word_list/searcher.rb