Class: SVGCommand
- Inherits:
-
Object
- Object
- SVGCommand
- Defined in:
- lib/convert_svg_string_to_gcode/models/svg_command.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_margins(x_margin, y_margin) ⇒ Object
- #adjust_by_proportion(proportion) ⇒ Object
-
#initialize(**params) ⇒ SVGCommand
constructor
A new instance of SVGCommand.
- #method_missing(name) ⇒ Object
Constructor Details
#initialize(**params) ⇒ SVGCommand
Returns a new instance of SVGCommand.
3 4 5 6 7 8 9 10 11 |
# File 'lib/convert_svg_string_to_gcode/models/svg_command.rb', line 3 def initialize(**params) @type = params[:type] @points = params.each_with_object({}) do |(param, value), hsh| unless ConversionConstants::VALID_CMD_ATTRIBUTES.include?(param) raise TypeError.new('Point label not defined') end hsh[param] = Float(value) unless value == nil || param == ConversionConstants::TYPE_LABEL end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
13 14 15 16 17 |
# File 'lib/convert_svg_string_to_gcode/models/svg_command.rb', line 13 def method_missing(name) super unless ConversionConstants::VALID_CMD_ATTRIBUTES.include? name value = @points[name] return value end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/convert_svg_string_to_gcode/models/svg_command.rb', line 2 def type @type end |
Instance Method Details
#add_margins(x_margin, y_margin) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/convert_svg_string_to_gcode/models/svg_command.rb', line 42 def add_margins(x_margin, y_margin) mutated_cp0x = self.cp0x+x_margin if self.cp0x mutated_cp0y = self.cp0y+y_margin if self.cp0y mutated_cp1x = self.cp1x+x_margin if self.cp1x mutated_cp1y = self.cp1y+y_margin if self.cp1y mutated_p0x = self.p0x+x_margin if self.p0x mutated_p0y = self.p0y+y_margin if self.p0y mutated_p1x = self.p1x+x_margin if self.p1x mutated_p1y = self.p1y+y_margin if self.p1y SVGCommand.new( type: @type, p0x: mutated_p0x, p0y: mutated_p0y, p1x: mutated_p1x, p1y: mutated_p1y, cp0x: mutated_cp0x, cp0y: mutated_cp0y, cp1x: mutated_cp1x, cp1y: mutated_cp1y, ) end |
#adjust_by_proportion(proportion) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/convert_svg_string_to_gcode/models/svg_command.rb', line 19 def adjust_by_proportion(proportion) mutated_cp0x = self.cp0x*proportion if self.cp0x mutated_cp0y = self.cp0y*proportion if self.cp0y mutated_cp1x = self.cp1x*proportion if self.cp1x mutated_cp1y = self.cp1y*proportion if self.cp1y mutated_p0x = self.p0x*proportion if self.p0x mutated_p0y = self.p0y*proportion if self.p0y mutated_p1x = self.p1x*proportion if self.p1x mutated_p1y = self.p1y*proportion if self.p1y SVGCommand.new( type: @type, cp0x: mutated_cp0x, cp0y: mutated_cp0y, cp1x: mutated_cp1x, cp1y: mutated_cp1y, p0x: mutated_p0x, p0y: mutated_p0y, p1x: mutated_p1x, p1y: mutated_p1y ) end |