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



45
46
47
48
49
50
# File 'lib/gcode.rb', line 45

def initialize(str)
  nodes = str.scan(/\d+|\D+/) # ["R", "01"]
  @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.



43
44
45
# File 'lib/gcode.rb', line 43

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



43
44
45
# File 'lib/gcode.rb', line 43

def tail
  @tail
end

Instance Method Details

#to_sObject



56
57
58
# File 'lib/gcode.rb', line 56

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

#to_symObject



52
53
54
# File 'lib/gcode.rb', line 52

def to_sym
  to_s.to_sym
end