Class: Boggler::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/boggler/grid.rb

Instance Method Summary collapse

Constructor Details

#initializeGrid

Returns a new instance of Grid.



3
4
5
6
7
8
9
10
# File 'lib/boggler/grid.rb', line 3

def initialize
  @grid = []

  @dice = Dice.get
  @size = Math.sqrt(@dice.length).to_i

  build_grid
end

Instance Method Details

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/boggler/grid.rb', line 12

def to_s
  row_strings = []

  @grid.each do |row|
    row_strings << row_string_for(row)
  end

  grid_string = separator
  row_strings.each do |row|
    grid_string += row
    grid_string += separator
  end

  grid_string
end

#wordsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/boggler/grid.rb', line 28

def words
  return @words if defined?(@words)

  @words = []

  @size.times do |i|
    @size.times do |j|
      words_starting_at(i + 1, j + 1)
    end
  end

  @words
end