class Savage::SubPath
Attributes
directions[RW]
Public Class Methods
new(*args) { |self| ... }
click to toggle source
# File lib/savage/sub_path.rb, line 22 def initialize(*args) @directions = [] 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/sub_path.rb, line 46 def closed? @directions.last.kind_of? Directions::ClosePath end
commands()
click to toggle source
# File lib/savage/sub_path.rb, line 42 def commands @directions end
fully_transformable?()
click to toggle source
# File lib/savage/sub_path.rb, line 74 def fully_transformable? directions.all? &:fully_transformable? end
move_to(*args)
click to toggle source
# File lib/savage/sub_path.rb, line 17 def move_to(*args) return nil unless @directions.empty? (@directions << Directions::MoveTo.new(*args)).last end
to_command()
click to toggle source
# File lib/savage/sub_path.rb, line 28 def to_command @directions.to_enum(:each_with_index).collect { |dir, i| command_string = dir.to_command if i > 0 prev_command_code = @directions[i-1].command_code if dir.command_code == prev_command_code || (prev_command_code.match(/^[Mm]$/) && dir.command_code == 'L') command_string.gsub!(/^[A-Za-z]/,'') command_string.insert(0,' ') unless command_string.match(/^-/) end end command_string }.join end
to_transformable_commands!()
click to toggle source
# File lib/savage/sub_path.rb, line 54 def to_transformable_commands! if !fully_transformable? pen_x, pen_y = 0, 0 directions.each_with_index do |dir, index| unless dir.fully_transformable? directions[index] = dir.to_fully_transformable_dir( pen_x, pen_y ) end dx, dy = dir.movement if dir.absolute? pen_x = dx if dx pen_y = dy if dy else pen_x += dx if dx pen_y += dy if dy end end end end
transform(*args)
click to toggle source
# File lib/savage/sub_path.rb, line 50 def transform(*args) directions.each { |dir| dir.transform *args } end