Permalink
Browse files

sketch compiler

  • Loading branch information...
1 parent 28dedea commit d2bfd1c8929e76fd8b1a0179118c5117d0ae45ab Greg Borenstein committed Aug 4, 2008
Showing with 52 additions and 0 deletions.
  1. +22 −0 lib/rad/sketch_compiler.rb
  2. +30 −0 spec/models/sketch_compiler_spec.rb
@@ -0,0 +1,22 @@
+# TODO:
+# compilation
+# gather pieces of code we need as strings
+# translate non-loop methods
+# do plugin stuff
+# deal with examples/ exception
+# manage upload process
+# from arduino_sketch.rb: compose_setup
+
+class SketchCompiler
+ attr_accessor :path, :body, :sketch_class
+
+ def initialize path_to_sketch
+ @path = File.expand_path(path_to_sketch)
+ @body = open(@path).read
+ @sketch_name = @path.split("/").last
+ @sketch_class = @sketch_name.split(".").first.split("_").collect{|c| c.capitalize}.join("")
+ end
+
+
+
+end
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/spec_helper.rb'
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/rad/sketch_compiler.rb")
+
+context "SketchCompiler.new" do
+ before do
+ @as = File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/add_hysteresis.rb"
+ end
+ it "should correctly absolutize a path with /../ that starts at /" do
+ SketchCompiler.new(@as).path.should == "/Users/greg/code/rad/lib/examples/add_hysteresis.rb"
+ end
+
+ it "should correct absolutize a relative path" do
+ SketchCompiler.new("lib/examples/add_hysteresis.rb").path.should == "/Users/greg/code/rad/lib/examples/add_hysteresis.rb"
+ end
+
+ it "should load the body of the sketch" do
+ sc = SketchCompiler.new @as
+ sc.body.should == open(@as).read
+ end
+
+end
+
+context "SketchCompiler#sketch_class" do
+ before do
+ @sc = SketchCompiler.new File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/add_hysteresis.rb"
+ end
+ it "should calculate correctly from the path" do
+ @sc.sketch_class.should == "AddHysteresis"
+ end
+end

0 comments on commit d2bfd1c

Please sign in to comment.