Class: WordSearch::ThreeDimensional::Plane

Inherits:
Plane::Base
  • Object
show all
Defined in:
lib/word_search/three_dimensional/plane.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, z) ⇒ Plane

Returns a new instance of Plane.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/word_search/three_dimensional/plane.rb', line 9

def initialize(x, y, z)
  @catalog = Catalog.new
  @x, @y, @z = x, y, z

  initialize_plane do |x_point, y_point|
    self[x_point][y_point] = {}
    z.times do |z_point|
      self[x_point][y_point][z_point] =
        Point.new(x_point, y_point, z_point)
    end
  end
end

Instance Attribute Details

#zObject

Returns the value of attribute z.



6
7
8
# File 'lib/word_search/three_dimensional/plane.rb', line 6

def z
  @z
end

Class Method Details

.make_from_file(file, should_catalog: true) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/word_search/three_dimensional/plane.rb', line 65

def make_from_file(file, should_catalog: true)
  string = File.read(file).split("\n\n").map(&:split)

  return false unless valid_file?(string)

  make_word_search(string, should_catalog: should_catalog)
end

Instance Method Details

#add_lettersObject



46
47
48
49
50
51
52
# File 'lib/word_search/three_dimensional/plane.rb', line 46

def add_letters
  super do |x_point, y_point|
    z.times do |z_point|
      self[x_point][y_point][z_point].letter ||= random_letter
    end
  end
end

#directionsObject



54
55
56
# File 'lib/word_search/three_dimensional/plane.rb', line 54

def directions
  @directions ||= WordSearch::ThreeDimensional::Direction
end

#find_next_point(point, direction) ⇒ Object



58
59
60
61
62
# File 'lib/word_search/three_dimensional/plane.rb', line 58

def find_next_point(point, direction)
  dig(
    point.x + direction[0], point.y + direction[1], point.z + direction[2]
  )
end

#maxObject



42
43
44
# File 'lib/word_search/three_dimensional/plane.rb', line 42

def max
  [x, y, z].max
end

#three_dimensional?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/word_search/three_dimensional/plane.rb', line 34

def three_dimensional?
  true
end

#to_sObject



22
23
24
25
26
27
28
# File 'lib/word_search/three_dimensional/plane.rb', line 22

def to_s
  (0..(z - 1)).map do |z_slice|
    values.map do |row|
      row.values.map { |ys| ys[z_slice] }.map(&:to_s)
    end.transpose.reverse.map(&:join).join("\n")
  end.join("\n\n")
end

#total_pointsObject



38
39
40
# File 'lib/word_search/three_dimensional/plane.rb', line 38

def total_points
  x * y * z
end

#two_dimensional?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/word_search/three_dimensional/plane.rb', line 30

def two_dimensional?
  false
end