Class: GCoder::GCode::ProgramContext

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/gcoder/gcode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position = [0,0,0], feedrate = 0, units = :mm, absolute = false) ⇒ ProgramContext

Returns a new instance of ProgramContext.



30
31
32
33
34
35
36
37
# File 'lib/gcoder/gcode.rb', line 30

def initialize(position = [0,0,0], feedrate = 0, units = :mm, absolute = false)
  super({})

  @position = position
  @feedrate = feedrate
  @units = units
  @absolute = absolute
end

Instance Attribute Details

#absoluteObject

Returns the value of attribute absolute.



28
29
30
# File 'lib/gcoder/gcode.rb', line 28

def absolute
  @absolute
end

#feedrateObject

Returns the value of attribute feedrate.



28
29
30
# File 'lib/gcoder/gcode.rb', line 28

def feedrate
  @feedrate
end

#positionObject

Returns the value of attribute position.



28
29
30
# File 'lib/gcoder/gcode.rb', line 28

def position
  @position
end

#unitsObject

Returns the value of attribute units.



28
29
30
# File 'lib/gcoder/gcode.rb', line 28

def units
  @units
end

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


39
# File 'lib/gcoder/gcode.rb', line 39

def absolute?; absolute; end

#update_feedrate(feedrate) ⇒ Object



49
50
51
# File 'lib/gcoder/gcode.rb', line 49

def update_feedrate(feedrate)
  @feedrate = feedrate unless feedrate.nil?
end

#update_position(pos) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/gcoder/gcode.rb', line 41

def update_position(pos)
  if absolute
    @position = @position.each_with_index.map {|e, i| pos[i] || @position[i] }
  else
    @position = @position.each_with_index.map {|e, i| @position[i] + (pos[i] || 0) }
  end
end