Class: WordSearch::Plane

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/word_search/plane.rb,
lib/word_search/plane/base.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.make_from_coordinates(x, y, z = nil) ⇒ Object



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

def self.make_from_coordinates(x, y, z = nil)
  obj =
    if z.present? && z > 1
      ThreeDimensional::Plane.new(x, y, z)
    else
      TwoDimensional::Plane.new(x, y)
    end

  new(obj)
end

.make_from_file(file, should_catalog: true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/word_search/plane.rb', line 5

def self.make_from_file(file, should_catalog: true)
  dimension =
    if File.read(file).split("\n\n").count > 1
      ThreeDimensional
    else
      TwoDimensional
    end

  obj =
    dimension::Plane.make_from_file(file, should_catalog: should_catalog)

  new(obj)
end

Instance Method Details

#to_sObject



30
31
32
33
34
35
36
# File 'lib/word_search/plane.rb', line 30

def to_s
  if invalid?
    errors.full_messages.join("\n")
  else
    super
  end
end