Class: FB::Gcode::GcodeToken
- Inherits:
-
Object
- Object
- FB::Gcode::GcodeToken
- Defined in:
- lib/gcode.rb
Overview
A head/tail pair of a single node of GCode. Ex: R01 = [:R, ‘01’]
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
-
#initialize(str) ⇒ GcodeToken
constructor
A new instance of GcodeToken.
- #to_s ⇒ Object
- #to_sym ⇒ Object
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
#head ⇒ Object (readonly)
Returns the value of attribute head.
50 51 52 |
# File 'lib/gcode.rb', line 50 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
50 51 52 |
# File 'lib/gcode.rb', line 50 def tail @tail end |
Instance Method Details
#to_s ⇒ Object
64 65 66 |
# File 'lib/gcode.rb', line 64 def to_s "#{head}#{tail}" end |
#to_sym ⇒ Object
60 61 62 |
# File 'lib/gcode.rb', line 60 def to_sym to_s.to_sym end |