Class: Svgcode::GCode::Converter
- Inherits:
-
Object
- Object
- Svgcode::GCode::Converter
- Defined in:
- lib/svgcode/gcode/converter.rb
Constant Summary collapse
- PX_PER_INCH =
300- PX_PER_MM =
PX_PER_INCH / 25.4
Instance Attribute Summary collapse
-
#finished ⇒ Object
readonly
Returns the value of attribute finished.
-
#max_y ⇒ Object
readonly
Returns the value of attribute max_y.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#transforms ⇒ Object
Returns the value of attribute transforms.
Instance Method Summary collapse
- #<<(str_or_command) ⇒ Object
- #comment!(str) ⇒ Object
- #finish ⇒ Object
-
#initialize(opts) ⇒ Converter
constructor
A new instance of Converter.
- #metric? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(opts) ⇒ Converter
Returns a new instance of Converter.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/svgcode/gcode/converter.rb', line 14 def initialize(opts) raise ArgumentError.new if opts.nil? || opts[:max_y].nil? @finished = false @transforms = [] @max_y = opts.delete(:max_y) @program = Program.new(opts) @metric = opts[:metric] != false @metric ? @program.metric! : @program.imperial! @program.feedrate! end |
Instance Attribute Details
#finished ⇒ Object (readonly)
Returns the value of attribute finished.
12 13 14 |
# File 'lib/svgcode/gcode/converter.rb', line 12 def finished @finished end |
#max_y ⇒ Object (readonly)
Returns the value of attribute max_y.
12 13 14 |
# File 'lib/svgcode/gcode/converter.rb', line 12 def max_y @max_y end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
12 13 14 |
# File 'lib/svgcode/gcode/converter.rb', line 12 def metric @metric end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
12 13 14 |
# File 'lib/svgcode/gcode/converter.rb', line 12 def program @program end |
#transforms ⇒ Object
Returns the value of attribute transforms.
11 12 13 |
# File 'lib/svgcode/gcode/converter.rb', line 11 def transforms @transforms end |
Instance Method Details
#<<(str_or_command) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/svgcode/gcode/converter.rb', line 25 def <<(str_or_command) @start = nil if str_or_command.is_a?(String) path = SVG::Path.new(str_or_command) path.commands.each { |cmd| add_command(cmd)} else cmd = SVG::Circle.new(str_or_command) add_command(cmd) end end |
#comment!(str) ⇒ Object
41 42 43 |
# File 'lib/svgcode/gcode/converter.rb', line 41 def comment!(str) @program.comment!(str) end |
#finish ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/svgcode/gcode/converter.rb', line 45 def finish unless @finished @program.clear! @program.go!(0, 0) @program.stop! @finished = true end end |
#metric? ⇒ Boolean
37 38 39 |
# File 'lib/svgcode/gcode/converter.rb', line 37 def metric? @metric end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/svgcode/gcode/converter.rb', line 54 def to_s @program.to_s end |