Class: GridGenerator::Cubic::SquareFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/cubic/square_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:, width_unit:, height_unit:, offset_unit:, face:) ⇒ SquareFactory

Returns a new instance of SquareFactory.



8
9
10
11
12
13
14
15
16
# File 'lib/grid_generator/cubic/square_factory.rb', line 8

def initialize(x:, y:, width_unit:, height_unit:, offset_unit:, face:)
  @x, @y = x, y
  @width_unit = width_unit
  @height_unit = height_unit
  @offset_unit = offset_unit
  face_attr = FaceParser.new(face).parse
  @colour = face_attr && face_attr[:colour]
  @opacity = face_attr && face_attr[:opacity]
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def colour
  @colour
end

#height_unitObject (readonly)

Returns the value of attribute height_unit.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def height_unit
  @height_unit
end

#offset_unitObject (readonly)

Returns the value of attribute offset_unit.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def offset_unit
  @offset_unit
end

#opacityObject (readonly)

Returns the value of attribute opacity.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def opacity
  @opacity
end

#width_unitObject (readonly)

Returns the value of attribute width_unit.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def width_unit
  @width_unit
end

#xObject (readonly)

Returns the value of attribute x.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



18
19
20
# File 'lib/grid_generator/cubic/square_factory.rb', line 18

def y
  @y
end

Instance Method Details

#bottom_leftObject



32
33
34
# File 'lib/grid_generator/cubic/square_factory.rb', line 32

def bottom_left
  top_left + height_unit
end

#bottom_rightObject



28
29
30
# File 'lib/grid_generator/cubic/square_factory.rb', line 28

def bottom_right
  top_left + width_unit + height_unit
end

#buildObject



45
46
47
# File 'lib/grid_generator/cubic/square_factory.rb', line 45

def build
  GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless colour.nil?
end

#pointsObject



36
37
38
39
40
41
42
43
# File 'lib/grid_generator/cubic/square_factory.rb', line 36

def points
  [
    top_left,
    top_right,
    bottom_right,
    bottom_left,
  ]
end

#top_leftObject



20
21
22
# File 'lib/grid_generator/cubic/square_factory.rb', line 20

def top_left
  Matrix.column_vector([x, y]) + offset_unit
end

#top_rightObject



24
25
26
# File 'lib/grid_generator/cubic/square_factory.rb', line 24

def top_right
  top_left + width_unit
end