class Savage::Path

Attributes

subpaths[RW]

Public Class Methods

new(*args) { |self| ... } click to toggle source
# File lib/savage/path.rb, line 18
def initialize(*args)
  @subpaths = [SubPath.new]
  @subpaths.last.move_to(*args) if (2..3).include?(*args.length)
  yield self if block_given?
end

Public Instance Methods

closed?() click to toggle source
# File lib/savage/path.rb, line 38
def closed?
  @subpaths.last.closed?
end
directions() click to toggle source
# File lib/savage/path.rb, line 24
def directions
  directions = []
  @subpaths.each { |subpath| directions.concat(subpath.directions) }
  directions
end
fully_transformable?() click to toggle source
# File lib/savage/path.rb, line 61
def fully_transformable?
  subpaths.all? &:fully_transformable?
end
move_to(*args) click to toggle source
# File lib/savage/path.rb, line 30
def move_to(*args)
  unless (@subpaths.last.directions.empty?)
    (@subpaths << SubPath.new(*args)).last
  else
    @subpaths.last.move_to(*args)
  end
end
to_command() click to toggle source
# File lib/savage/path.rb, line 42
def to_command
  @subpaths.collect { |subpath| subpath.to_command }.join
end
to_transformable_commands!() click to toggle source

Public: make commands within transformable commands

H/h/V/v is considered not 'transformable'
because when they are rotated, they will
turn into other commands
# File lib/savage/path.rb, line 57
def to_transformable_commands!
  subpaths.each &:to_transformable_commands!
end
transform(*args) click to toggle source
# File lib/savage/path.rb, line 46
def transform(*args)
  dup.tap do |path|
    path.to_transformable_commands!
    path.subpaths.each {|subpath| subpath.transform *args }
  end
end