Top level object.
internal method
# File lib/mathviz.rb, line 84 def self.default_term @@default_term ||= Constant end
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
# 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
Turn the object into a MathViz::Term (MathViz::Constant) if isn’t already a MathViz::Term. This allows for operator parameters to be primitive values without needing MathViz#const, MathViz#input, or units.
# File lib/mathviz.rb, line 89 def self.term(x) if (x.kind_of?(MathViz::Term)) x else MathViz::Constant.new(x) end end
Comment which reads a little better than repetition.
# File lib/mathviz.rb, line 80 def And(desc) end
Comment that identifies a set of constants. Subsequent measured values will be marked as const
# File lib/mathviz.rb, line 70 def Given(desc) @@default_term = Constant end
Comment that identifies a section of calculations on the inputs and constants.
# File lib/mathviz.rb, line 75 def Then(desc) @@default_term = Constant end
Comment that identifies a set of inputs. Subsequent measured values will be marked as input
# File lib/mathviz.rb, line 65 def When(desc) @@default_term = Input end
Define op as a binary operator
# File lib/mathviz.rb, line 40 def binop(op) MathViz::Term.binop op MathViz::Unit.binop op end
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Constant)
# File lib/mathviz.rb, line 24 def const(x) MathViz::Constant.new(x) end
Save a Graphviz .dot file in the current directory, with name specified in the constructor. Triggers most of the actual processsing.
# File lib/mathviz.rb, line 51 def dot MathViz::Term.name_terms!(@env) #puts MathViz::Term.list_terms(@env).map {|t| t.long} graph = GraphvizR.new @name MathViz::Term.list_terms(@env).flat_map(&:collapse).each {|t| t.to_dot(graph) } filename = @name + '.dot' graph.output(filename, 'dot') puts "Wrote #{filename}" end
Convert a basic value (typically Numeric) into a MathViz::Term (MathViz::Input)
# File lib/mathviz.rb, line 29 def input(x) MathViz::Input.new(x) end
Define new units (instance methods) on module MathViz::Units (where they will be picked up by everything including the module) Defined methods are essentialy aliases for unit(name); see MathViz::Measurable / MathViz::Measured
# File lib/mathviz.rb, line 35 def new_units(*units) MathViz::Units.new_units(*units) end
Generated with the Darkfish Rdoc Generator 2.