Sha256: 9ef8f1d1dbc2d9f31ad7b607d73a105eb03c8fa508f54e4d763c5b0ecd0d49c9

Contents?: true

Size: 822 Bytes

Versions: 19

Compression:

Stored size: 822 Bytes

Contents

module GridGenerator
  class BaseLine
    COLOURS = {
      fill: "#d0d0d0",
      stroke: "#404040"
    }

    def initialize(a:, b:)
      @a, @b = a, b
    end

    attr_reader :a, :b

    def ==(other)
      self.class == other.class &&
        self.a == other.a &&
        self.b == other.b
    end

    def +(offset)
      if offset.class == Matrix
        new_a = a + offset
        new_b = b + offset
        self.class.new(a: new_a, b: new_b)
      else
        raise ArgumentError, "Offset must be Matrix"
      end
    end

    def x1
      a[0,0]
    end

    def y1
      a[1,0]
    end

    def x2
      b[0,0]
    end

    def y2
      b[1,0]
    end

    def to_svg
      "<line x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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