Created
January 28, 2011 10:27
-
-
Save jamescook/800084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/rmodeling/dsl.rb b/lib/rmodeling/dsl.rb | |
new file mode 100644 | |
index 0000000..ff1a795 | |
--- /dev/null | |
+++ b/lib/rmodeling/dsl.rb | |
@@ -0,0 +1,30 @@ | |
+module RModeling | |
+ module DSL | |
+ def self.included(base) | |
+ base.send(:include, InstanceMethods) | |
+ end | |
+ | |
+ | |
+ module InstanceMethods | |
+ def scene *args, &block | |
+ @scene = Scene.new args | |
+ @scene.instance_eval(&block) if block_given? | |
+ @scene | |
+ end | |
+ | |
+ def valve *args, &block | |
+ name, output = args | |
+ _valve = Valve.new(name, output) | |
+ @scene.args << _valve | |
+ @scene.instance_eval(&block) if block_given? | |
+ end | |
+ | |
+ def accumulator *args, &block | |
+ name, initial_value = args | |
+ _accumulator = Accumulator.new(name, initial_value) | |
+ @scene.args << _accumulator | |
+ @scene.instance_eval(&block) if block_given? | |
+ end | |
+ end | |
+ end | |
+end | |
diff --git a/lib/rmodeling/scene.rb b/lib/rmodeling/scene.rb | |
index 5e56ff8..0f79d4d 100644 | |
--- a/lib/rmodeling/scene.rb | |
+++ b/lib/rmodeling/scene.rb | |
@@ -6,8 +6,10 @@ module RModeling | |
@args = args | |
@nodes = {} | |
args.each do |arg| | |
- arg.scene = self | |
- nodes[arg.name] = arg | |
+ if arg.respond_to?(:scene) | |
+ arg.scene = self | |
+ nodes[arg.name] = arg | |
+ end | |
end | |
@current_step = 0 | |
end | |
@@ -46,5 +48,17 @@ module RModeling | |
def get_node name | |
nodes[name] | |
end | |
+ | |
+ def valve *args | |
+ yield *args if block_given? | |
+ end | |
+ | |
+ def accumulator *args | |
+ yield *args if block_given? | |
+ end | |
+ | |
+ def plot | |
+ GnuPlotter.new(self).plot | |
+ end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment