Sha256: 8f63900c51a0eee66c952de98e22acf7c390b1a182691d3430fbcb285d144654

Contents?: true

Size: 737 Bytes

Versions: 18

Compression:

Stored size: 737 Bytes

Contents

module GridGenerator
  module Svg 
    class PathCommand 
      def initialize(points: []) 
        @points = points
      end

      attr_reader :points

      def type
        'M'
      end

      def +(offset)
        if offset.class == Matrix 
          new_points = points.map { |p| p + offset }
          self.class.new(points: new_points)
        else
          raise ArgumentError, "Offset must be Matrix"
        end
      end

      def ==(other)
        self.class == other.class && self.points == other.points
      end

      def to_s
        [type, points_string].join(' ')
      end

      private

      def points_string
        points.map { |p| "#{p[0,0].round} #{p[1,0].round}" }.join(' ')
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
grid_generator-0.6.7 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.6 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.5 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.4 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.3 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.2 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.1 lib/grid_generator/svg/path_command.rb
grid_generator-0.6.0 lib/grid_generator/svg/path_command.rb
grid_generator-0.5.3 lib/grid_generator/svg/path_command.rb
grid_generator-0.5.2 lib/grid_generator/svg/path_command.rb
grid_generator-0.5.1 lib/grid_generator/svg/path_command.rb
grid_generator-0.5.0 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.5 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.4 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.3 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.2 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.1 lib/grid_generator/svg/path_command.rb
grid_generator-0.4.0 lib/grid_generator/svg/path_command.rb