Class: Svgcode::GCode::Converter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Converter

Returns a new instance of Converter.

Raises:

  • (ArgumentError)


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

#finishedObject (readonly)

Returns the value of attribute finished.



12
13
14
# File 'lib/svgcode/gcode/converter.rb', line 12

def finished
  @finished
end

#max_yObject (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

#metricObject (readonly)

Returns the value of attribute metric.



12
13
14
# File 'lib/svgcode/gcode/converter.rb', line 12

def metric
  @metric
end

#programObject (readonly)

Returns the value of attribute program.



12
13
14
# File 'lib/svgcode/gcode/converter.rb', line 12

def program
  @program
end

#transformsObject

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

#finishObject



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

Returns:

  • (Boolean)


37
38
39
# File 'lib/svgcode/gcode/converter.rb', line 37

def metric?
  @metric
end

#to_sObject



54
55
56
# File 'lib/svgcode/gcode/converter.rb', line 54

def to_s
  @program.to_s
end