Class: MathViz
Overview
Top level object.
Defined Under Namespace
Modules: Measurable, Measured, Units Classes: Constant, Input, Operation, Term, Unit
Constant Summary collapse
- VERSION =
RubyGem version
'1.0.1'
- Infinity =
Something to return instead of dividing by zero, etc.
1.0/0
Instance Method Summary collapse
-
#const(x) ⇒ Object
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Constant).
-
#dot ⇒ Object
Save a Graphviz .dot file in the current directory, with name specified in the constructor.
-
#initialize(name = nil, bind = nil, &proc) ⇒ MathViz
constructor
-
base name of the output file.
-
-
#input(x) ⇒ Object
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Input).
Constructor Details
#initialize(name = nil, bind = nil, &proc) ⇒ MathViz
-
base name of the output file. If omitted(falsy) it will use the top level program name.
-
Binding object, as if from ‘binding’
-
A proc which returns a binding.
If bind is passed, the proc will not be executed. If bind is falsy, the proc will be executed and it’s return value stored.
The proc is evaluated in the context of the new MathViz instance, making #const and #input directly available
18 19 20 21 |
# File 'lib/mathviz.rb', line 18 def initialize(name = nil, bind = nil, &proc) @name = name || File.basename($PROGRAM_NAME, '.rb') @env = bind || instance_eval(&proc) end |
Instance Method Details
#const(x) ⇒ Object
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Constant)
24 25 26 |
# File 'lib/mathviz.rb', line 24 def const(x) MathViz::Constant.new(x) end |
#dot ⇒ Object
Save a Graphviz .dot file in the current directory, with name specified in the constructor. Triggers most of the actual processsing.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mathviz.rb', line 34 def dot MathViz::Term.name_terms!(@env) #puts MathViz::Term.list_terms(@env).map {|t| t.long} graph = GraphvizR.new @name graph = MathViz::Term.list_terms(@env).inject(graph) {|g, t| t.to_dot(g) g } #puts graph.to_dot graph.output(@name + '.dot', 'dot') end |
#input(x) ⇒ Object
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Input)
29 30 31 |
# File 'lib/mathviz.rb', line 29 def input(x) MathViz::Input.new(x) end |