Class: Savage::Path

Inherits:
Object
  • Object
show all
Includes:
DirectionProxy, Utils
Defined in:
lib/savage/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DirectionProxy

included

Methods included from Utils

#bool_to_int

Constructor Details

#initialize(*args) {|_self| ... } ⇒ Path

Returns a new instance of Path.

Yields:

  • (_self)

Yield Parameters:

  • _self (Savage::Path)

    the object that the method was called on



17
18
19
20
21
# File 'lib/savage/path.rb', line 17

def initialize(*args)
  @subpaths = [SubPath.new]
  @subpaths.last.move_to(*args) if (2..3).include?(*args.length)
  yield self if block_given?
end

Instance Attribute Details

#subpathsObject

Returns the value of attribute subpaths.



9
10
11
# File 'lib/savage/path.rb', line 9

def subpaths
  @subpaths
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/savage/path.rb', line 37

def closed?
  @subpaths.last.closed?
end

#directionsObject



23
24
25
26
27
# File 'lib/savage/path.rb', line 23

def directions
  directions = []
  @subpaths.each { |subpath| directions.concat(subpath.directions) }
  directions
end

#move_to(*args) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/savage/path.rb', line 29

def move_to(*args)
  unless (@subpaths.last.directions.empty?)
    (@subpaths << SubPath.new(*args)).last
  else
    @subpaths.last.move_to(*args)
  end
end

#to_commandObject



41
42
43
# File 'lib/savage/path.rb', line 41

def to_command
  @subpaths.collect { |subpath| subpath.to_command }.join
end