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'))
- PARAMETER_DICTIONARY =
YAML.load_file(File.join(File.dirname(__FILE__), 'parameters.yml'))
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#params ⇒ Object
Returns the value of attribute params.
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(&block) ⇒ Gcode
constructor
A new instance of Gcode.
-
#name ⇒ Object
Returns a symbolized english version of the gcode’s name.
- #to_s ⇒ Object
- #value_of(param) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Gcode
Returns a new instance of Gcode.
11 12 13 |
# File 'lib/gcode.rb', line 11 def initialize(&block) @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
9 10 11 |
# File 'lib/gcode.rb', line 9 def block @block end |
#cmd ⇒ Object
Returns the value of attribute cmd.
9 10 11 |
# File 'lib/gcode.rb', line 9 def cmd @cmd end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/gcode.rb', line 9 def params @params 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.
17 18 19 |
# File 'lib/gcode.rb', line 17 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.
22 23 24 |
# File 'lib/gcode.rb', line 22 def name GCODE_DICTIONARY[cmd.to_sym] || :unknown end |
#to_s ⇒ Object
26 27 28 29 |
# File 'lib/gcode.rb', line 26 def to_s # self.to_s # => "A12 B23 C45" [cmd, *params].map(&:to_s).join(" ") end |
#value_of(param) ⇒ Object
44 45 46 |
# File 'lib/gcode.rb', line 44 def value_of(param) params.find{ |p| p.head == param.to_sym.upcase }.tail end |