class SketchCompiler

require ‘arduino_sketch’

Attributes

body[RW]
klass[RW]
name[RW]
path[RW]
target_dir[RW]

Public Class Methods

new(path_to_sketch) click to toggle source
# 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

Public Instance Methods

build_dir() click to toggle source
# File lib/rad/sketch_compiler.rb, line 27
def build_dir
  "#{self.target_dir}/#{self.name}"
end
create_build_dir!(optional_path_prefix=nil) click to toggle source
# 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() click to toggle source
# File lib/rad/sketch_compiler.rb, line 23
def parent_dir
  self.path.split("/")[0..@path.split("/").length-2].join("/")
end
process_constants() click to toggle source
# 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() click to toggle source
# 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