Class: FB::Gcode
- Inherits:
-
Object
- Object
- FB::Gcode
- Defined in:
- lib/gcode.rb
Defined Under Namespace
Classes: GcodeToken
Constant Summary collapse
- GCODE_DICTIONARY =
YAML.load_file(File.join(File.dirname(__FILE__), 'gcode.yml'))
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#params ⇒ Object
Returns the value of attribute params.
-
#str ⇒ Object
Returns the value of attribute str.
Class Method Summary collapse
-
.parse_lines(string) ⇒ Object
Turns a string of many gcodes into an array of many gcodes.
Instance Method Summary collapse
-
#initialize(str) ⇒ Gcode
constructor
A new instance of Gcode.
-
#name ⇒ Object
Returns a symbolized english version of the gcode’s name.
- #to_s ⇒ Object
Constructor Details
#initialize(str) ⇒ Gcode
Returns a new instance of Gcode.
8 9 10 11 12 |
# File 'lib/gcode.rb', line 8 def initialize(str) @str = str @params = str.split(' ').map{|line| GcodeToken.new(line)} @cmd = @params.shift || 'NULL' end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/gcode.rb', line 6 def cmd @cmd end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/gcode.rb', line 6 def params @params end |
#str ⇒ Object
Returns the value of attribute str.
6 7 8 |
# File 'lib/gcode.rb', line 6 def str @str end |
Class Method Details
.parse_lines(string) ⇒ Object
Turns a string of many gcodes into an array of many gcodes. Used to parse incoming serial.
16 17 18 |
# File 'lib/gcode.rb', line 16 def self.parse_lines(string) string.gsub("\r", '').split("\n").map { |s| self.new(s) } end |
Instance Method Details
#name ⇒ Object
Returns a symbolized english version of the gcode’s name.
21 22 23 |
# File 'lib/gcode.rb', line 21 def name GCODE_DICTIONARY[cmd.to_sym] || :unknown end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/gcode.rb', line 25 def to_s [@cmd, *@params].map(&:to_s).join(" ") end |