Class: WordSearch::ThreeDimensional::Plane
- Inherits:
-
Plane::Base
- Object
- Plane::Base
- WordSearch::ThreeDimensional::Plane
- Defined in:
- lib/word_search/three_dimensional/plane.rb
Instance Attribute Summary collapse
-
#z ⇒ Object
Returns the value of attribute z.
Class Method Summary collapse
Instance Method Summary collapse
- #add_letters ⇒ Object
- #directions ⇒ Object
- #find_next_point(point, direction) ⇒ Object
-
#initialize(x, y, z) ⇒ Plane
constructor
A new instance of Plane.
- #max ⇒ Object
- #three_dimensional? ⇒ Boolean
- #to_s ⇒ Object
- #total_points ⇒ Object
- #two_dimensional? ⇒ Boolean
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
#z ⇒ Object
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_letters ⇒ Object
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 |
#directions ⇒ Object
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 |
#max ⇒ Object
42 43 44 |
# File 'lib/word_search/three_dimensional/plane.rb', line 42 def max [x, y, z].max end |
#three_dimensional? ⇒ Boolean
34 35 36 |
# File 'lib/word_search/three_dimensional/plane.rb', line 34 def three_dimensional? true end |
#to_s ⇒ Object
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_points ⇒ Object
38 39 40 |
# File 'lib/word_search/three_dimensional/plane.rb', line 38 def total_points x * y * z end |
#two_dimensional? ⇒ Boolean
30 31 32 |
# File 'lib/word_search/three_dimensional/plane.rb', line 30 def two_dimensional? false end |