Class: SketchCompiler
- Inherits:
-
Object
- Object
- SketchCompiler
- Defined in:
- lib/rad/sketch_compiler.rb
Overview
require ‘arduino_sketch’
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#target_dir ⇒ Object
Returns the value of attribute target_dir.
Instance Method Summary collapse
- #build_dir ⇒ Object
- #create_build_dir!(optional_path_prefix = nil) ⇒ Object
-
#initialize(path_to_sketch) ⇒ SketchCompiler
constructor
A new instance of SketchCompiler.
- #parent_dir ⇒ Object
- #process_constants ⇒ Object
- #sketch_methods ⇒ Object
Constructor Details
#initialize(path_to_sketch) ⇒ SketchCompiler
Returns a new instance of SketchCompiler.
15 16 17 18 19 20 21 |
# File 'lib/rad/sketch_compiler.rb', line 15 def initialize path_to_sketch @path = File.(path_to_sketch) @body = open(@path).read @name = @path.split("/").last.split(".").first @klass = @name.split(".").first.split("_").collect{|c| c.capitalize}.join("") @target_dir = parent_dir end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
13 14 15 |
# File 'lib/rad/sketch_compiler.rb', line 13 def body @body end |
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/rad/sketch_compiler.rb', line 13 def klass @klass end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/rad/sketch_compiler.rb', line 13 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/rad/sketch_compiler.rb', line 13 def path @path end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
13 14 15 |
# File 'lib/rad/sketch_compiler.rb', line 13 def target_dir @target_dir end |
Instance Method Details
#build_dir ⇒ Object
27 28 29 |
# File 'lib/rad/sketch_compiler.rb', line 27 def build_dir "#{self.target_dir}/#{self.name}" end |
#create_build_dir!(optional_path_prefix = nil) ⇒ Object
31 32 33 34 |
# File 'lib/rad/sketch_compiler.rb', line 31 def create_build_dir! optional_path_prefix=nil self.target_dir = optional_path_prefix if optional_path_prefix mkdir_p build_dir end |
#parent_dir ⇒ Object
23 24 25 |
# File 'lib/rad/sketch_compiler.rb', line 23 def parent_dir self.path.split("/")[0..@path.split("/").length-2].join("/") end |
#process_constants ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rad/sketch_compiler.rb', line 36 def process_constants self.body.gsub!("HIGH", "1") self.body.gsub!("LOW", "0") self.body.gsub!("ON", "1") self.body.gsub!("OFF", "0") end |
#sketch_methods ⇒ Object
43 44 45 |
# File 'lib/rad/sketch_compiler.rb', line 43 def sketch_methods self.body.scan(/^\s*def\s.\w*/).collect{ |m| m.gsub(/\s*def\s*/, "") } end |