Class: GridGenerator::BaseElement
- Inherits:
-
Object
- Object
- GridGenerator::BaseElement
- Defined in:
- lib/grid_generator/base_element.rb
Constant Summary collapse
- COLOURS =
{ fill: "#d0d0d0", stroke: "#404040" }
Instance Attribute Summary collapse
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json ⇒ Object
-
#initialize(points:, colour:, opacity: 1) ⇒ BaseElement
constructor
A new instance of BaseElement.
- #points_string ⇒ Object
- #to_svg ⇒ Object
Constructor Details
#initialize(points:, colour:, opacity: 1) ⇒ BaseElement
Returns a new instance of BaseElement.
8 9 10 11 12 |
# File 'lib/grid_generator/base_element.rb', line 8 def initialize(points:, colour: , opacity: 1) @points = points @colour = colour @opacity = opacity end |
Instance Attribute Details
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
14 15 16 |
# File 'lib/grid_generator/base_element.rb', line 14 def colour @colour end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
14 15 16 |
# File 'lib/grid_generator/base_element.rb', line 14 def opacity @opacity end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
14 15 16 |
# File 'lib/grid_generator/base_element.rb', line 14 def points @points end |
Instance Method Details
#==(other) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/grid_generator/base_element.rb', line 16 def ==(other) self.class == other.class && self.points == other.points && self.colour == other.colour && self.opacity == other.opacity end |
#as_json ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/grid_generator/base_element.rb', line 27 def as_json { "points_string" => points_string, "colour" => colour, "opacity" => opacity } end |
#points_string ⇒ Object
23 24 25 |
# File 'lib/grid_generator/base_element.rb', line 23 def points_string points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ') end |
#to_svg ⇒ Object
35 36 37 |
# File 'lib/grid_generator/base_element.rb', line 35 def to_svg "<polygon points=\"#{points_string}\" style=\"fill:#{colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{opacity}\" />" end |