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
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
#head ⇒ Object (readonly)
Returns the value of attribute head.
43 44 45 |
# File 'lib/gcode.rb', line 43 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
43 44 45 |
# File 'lib/gcode.rb', line 43 def tail @tail end |
Instance Method Details
#to_s ⇒ Object
56 57 58 |
# File 'lib/gcode.rb', line 56 def to_s "#{head}#{tail}" end |
#to_sym ⇒ Object
52 53 54 |
# File 'lib/gcode.rb', line 52 def to_sym to_s.to_sym end |