Class: GridGenerator::Cubic::UnitsFactory
- Inherits:
-
Object
- Object
- GridGenerator::Cubic::UnitsFactory
- Defined in:
- lib/grid_generator/cubic/units_factory.rb
Instance Attribute Summary collapse
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #build ⇒ Object
- #front_unit ⇒ Object
-
#initialize(side:, type:, units:) ⇒ UnitsFactory
constructor
A new instance of UnitsFactory.
- #right_unit ⇒ Object
- #top_unit ⇒ Object
Constructor Details
#initialize(side:, type:, units:) ⇒ UnitsFactory
Returns a new instance of UnitsFactory.
4 5 6 7 8 9 10 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 4 def initialize(side:, type:, units:) raise ArgumentError "Unknown Side" unless [:top, :front, :right].include?(side) raise ArgumentError "Unknown Type" unless [:width, :height, :offset].include?(type) @side = side @type = type @units = units end |
Instance Attribute Details
#side ⇒ Object (readonly)
Returns the value of attribute side.
12 13 14 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 12 def side @side end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 12 def type @type end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
12 13 14 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 12 def units @units end |
Instance Method Details
#build ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 47 def build case side when :top top_unit when :front front_unit when :right right_unit end end |
#front_unit ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 25 def front_unit case type when :width Matrix.column_vector([units, units/2]) when :height Matrix.column_vector([0, units]) when :offset Matrix.column_vector([0,0]) end end |
#right_unit ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 36 def right_unit case type when :width Matrix.column_vector([units, (units*-0.5).to_i]) when :height Matrix.column_vector([0, units]) when :offset Matrix.column_vector([0,(units*0.5).to_i]) end end |
#top_unit ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/grid_generator/cubic/units_factory.rb', line 14 def top_unit case type when :width Matrix.column_vector([units, units/2]) when :height Matrix.column_vector([-units, units/2]) when :offset Matrix.column_vector([units,0]) end end |