Class: DYI::Shape::Path::LineCommand

Inherits:
CommandBase show all
Defined in:
lib/dyi/shape/path.rb

Overview

Since:

  • 0.0.0

Direct Known Subclasses

HorizontalLineCommand, VerticalLineCommand

Instance Attribute Summary

Attributes inherited from CommandBase

#point, #preceding_command

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBase

#absolute?, absolute_commands, #last_point, #preceding_point, #relative?, relative_commands, #start_point, #to_compatible_commands, #used_same_command?

Constructor Details

#initialize(relative, preceding_command, point) ⇒ LineCommand

Returns a new instance of LineCommand.

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



732
733
734
735
# File 'lib/dyi/shape/path.rb', line 732

def initialize(relative, preceding_command, point)
  raise ArgumentError, 'preceding_command is nil' if preceding_command.nil?
  super
end

Class Method Details

.commands(relative, preceding_command, *points) ⇒ Object

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



746
747
748
749
750
751
752
# File 'lib/dyi/shape/path.rb', line 746

def commands(relative, preceding_command, *points)
  raise ArgumentError, 'wrong number of arguments (2 for 3)' if points.empty?
  cmd = preceding_command
  points.inject([]) do |cmds, pt|
    cmds << (cmd = new(relative, cmd, pt))
  end
end

Instance Method Details

#instructions_charObject

Since:

  • 0.0.0



741
742
743
# File 'lib/dyi/shape/path.rb', line 741

def instructions_char
  relative? ? 'l' : 'L'
end

#to_concise_syntax_fragmentsObject

Since:

  • 0.0.0



737
738
739
# File 'lib/dyi/shape/path.rb', line 737

def to_concise_syntax_fragments
  used_same_command? ? @point.to_s : (instructions_char + @point.to_s)
end