Class: FB::Gcode::GcodeToken

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

Overview

A head/tail pair of a single node of GCode. Ex: R01 = [:R, ‘01’]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ GcodeToken

Returns a new instance of GcodeToken.



52
53
54
55
56
57
58
# File 'lib/gcode.rb', line 52

def initialize(str)
  nodes = str.scan(/[a-zA-Z]+|\-?\d+/) # ["R", "-19"], ["Z", "4"]

  @head, @tail = nodes.shift.to_sym, nodes.join(" ")
  # Coerce to ints if possible, since serial line is all string types.
  @tail = @tail.to_i if @tail.match(/^\-?\d+$/)
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



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

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



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

def tail
  @tail
end

Instance Method Details

#to_sObject



64
65
66
# File 'lib/gcode.rb', line 64

def to_s
  "#{head}#{tail}"
end

#to_symObject



60
61
62
# File 'lib/gcode.rb', line 60

def to_sym
  to_s.to_sym
end