Sha256: bf5e9a04bd3f04ddd7eeb1b2c337532c83ca5780eeab7c8a9748817e154ddcb3

Contents?: true

Size: 870 Bytes

Versions: 20

Compression:

Stored size: 870 Bytes

Contents

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

    def initialize(points:, colour: , opacity: 1)
      @points = points
      @colour = colour
      @opacity = opacity
    end

    attr_reader :points, :colour, :opacity

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

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

    def as_json
      {
        "points_string" => points_string,
        "colour" => colour,
        "opacity" => opacity
      }
    end

    def to_svg
      "<polygon points=\"#{points_string}\" style=\"fill:#{colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{opacity}\" />"
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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