Class: WordSearch::TwoDimensional::Plane
- Inherits:
-
Plane::Base
- Object
- Plane::Base
- WordSearch::TwoDimensional::Plane
- Defined in:
- lib/word_search/two_dimensional/plane.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_letters ⇒ Object
- #directions ⇒ Object
- #find_next_point(point, direction) ⇒ Object
-
#initialize(x, y) ⇒ Plane
constructor
A new instance of Plane.
- #max ⇒ Object
- #to_s ⇒ Object
- #total_points ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Plane
Returns a new instance of Plane.
6 7 8 9 10 11 12 13 |
# File 'lib/word_search/two_dimensional/plane.rb', line 6 def initialize(x, y) @catalog = Catalog.new @x, @y = x, y initialize_plane do |x_point, y_point| self[x_point][y_point] = Point.new(x_point, y_point) end end |
Class Method Details
.make_from_file(file, should_catalog: true) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/word_search/two_dimensional/plane.rb', line 44 def make_from_file(file, should_catalog: true) string = File.read(file).split("\n").reverse return false if (x_len = string.collect(&:length).uniq).count > 1 || x_len.blank? make_word_search(x_len, string, should_catalog: should_catalog) end |
Instance Method Details
#add_letters ⇒ Object
21 22 23 24 25 |
# File 'lib/word_search/two_dimensional/plane.rb', line 21 def add_letters super do |x_point, y_point| self[x_point][y_point].letter ||= random_letter end end |
#directions ⇒ Object
35 36 37 |
# File 'lib/word_search/two_dimensional/plane.rb', line 35 def directions @directions ||= WordSearch::TwoDimensional::Direction end |
#find_next_point(point, direction) ⇒ Object
39 40 41 |
# File 'lib/word_search/two_dimensional/plane.rb', line 39 def find_next_point(point, direction) dig(point.x + direction[0], point.y + direction[1]) end |
#max ⇒ Object
31 32 33 |
# File 'lib/word_search/two_dimensional/plane.rb', line 31 def max [x, y].max end |
#to_s ⇒ Object
15 16 17 18 19 |
# File 'lib/word_search/two_dimensional/plane.rb', line 15 def to_s values.map do |row| row.values.map(&:letter) end.transpose.reverse.map(&:join).join("\n") end |
#total_points ⇒ Object
27 28 29 |
# File 'lib/word_search/two_dimensional/plane.rb', line 27 def total_points x * y end |