Class: SketchCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/sketch_compiler.rb

Overview

require ‘arduino_sketch’

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(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

#bodyObject

Returns the value of attribute body.



13
14
15
# File 'lib/rad/sketch_compiler.rb', line 13

def body
  @body
end

#klassObject

Returns the value of attribute klass.



13
14
15
# File 'lib/rad/sketch_compiler.rb', line 13

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/rad/sketch_compiler.rb', line 13

def name
  @name
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/rad/sketch_compiler.rb', line 13

def path
  @path
end

#target_dirObject

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_dirObject



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_dirObject



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_constantsObject



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_methodsObject



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