Class: GridGenerator::Svg::Polygon

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/svg/polygon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points:, style:) ⇒ Polygon

Returns a new instance of Polygon.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/grid_generator/svg/polygon.rb', line 4

def initialize(points: , style:)
  @points = case points
            when Array
              points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
            when String
              points
            else
              raise ArgumentError, "points must be Array or String" 
            end
  @style = case style
           when GridGenerator::Svg::Style
             style.to_s
           when String
             style
           else
             raise ArgumentError, "style must be String or Style" 
           end
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



23
24
25
# File 'lib/grid_generator/svg/polygon.rb', line 23

def points
  @points
end

#styleObject (readonly)

Returns the value of attribute style.



23
24
25
# File 'lib/grid_generator/svg/polygon.rb', line 23

def style
  @style
end

Instance Method Details

#to_svgObject



25
26
27
# File 'lib/grid_generator/svg/polygon.rb', line 25

def to_svg
  "<polygon points=\"#{points}\" style=\"#{style.to_s}\" />"
end