In Files

Parent

Files

MathViz

Top level object.

Constants

Infinity

Something to return instead of dividing by zero, etc.

VERSION

RubyGem version

Public Class Methods

default_term() click to toggle source

internal method

# File lib/mathviz.rb, line 84
def self.default_term
  @@default_term ||= Constant
end
new(name = nil, bind = nil, &proc) click to toggle source
  • 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
term(x) click to toggle source

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

Public Instance Methods

And(desc) click to toggle source

Comment which reads a little better than repetition.

# File lib/mathviz.rb, line 80
def And(desc)
end
Given(desc) click to toggle source

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
Then(desc) click to toggle source

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
When(desc) click to toggle source

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
binop(op) click to toggle source

Define op as a binary operator

# File lib/mathviz.rb, line 40
def binop(op)
  MathViz::Term.binop op
  MathViz::Unit.binop op
end
const(x) click to toggle source

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
dot() click to toggle source

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
input(x) click to toggle source

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
new_units(*units) click to toggle source

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
unop(op) click to toggle source

Define op as unary operator

# File lib/mathviz.rb, line 46
def unop(op)
  MathViz::Term.unop op
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.