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.



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

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.



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

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



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

def tail
  @tail
end

Instance Method Details

#to_sObject



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

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

#to_symObject



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

def to_sym
  to_s.to_sym
end