Sha256: 0166191a39cb3868ba2302db842212620a8fc213cee4cec7b469357de7abadcb

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 Bytes

Contents

module Savage
  class Path
    require File.dirname(__FILE__) + "/direction_proxy"
    require File.dirname(__FILE__) + "/sub_path"

    include Utils
    include DirectionProxy

    attr_accessor :subpaths

    define_proxies do |sym,const|
      define_method(sym) do |*args|
        @subpaths.last.send(sym,*args)
      end
    end

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

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

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

    def closed?
      @subpaths.last.closed?
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
savage-1.2.0 lib/savage/path.rb