Class: MathViz::Operation::Unary
- Inherits:
-
MathViz::Operation
- Object
- Term
- MathViz::Operation
- MathViz::Operation::Unary
- Defined in:
- lib/mathviz.rb
Overview
Display and processing for single-value operators
Instance Attribute Summary
Attributes inherited from Term
Instance Method Summary collapse
-
#constant? ⇒ Boolean
Forward to contained value.
-
#initialize(a, op) ⇒ Unary
constructor
A new instance of Unary.
-
#long ⇒ Object
Debugging method; return string of name and value.
-
#to_dot(g) ⇒ Object
Extend Graphviz g with a representation of this object, and incoming connections.
-
#to_f ⇒ Object
Apply the operator to create the derived value.
-
#units ⇒ Object
Forward to contained value.
Methods inherited from MathViz::Operation
Methods inherited from Term
binop, #color, #data, #label, list_terms, name_terms!, #shape, #style, #to_i, #to_s, unop
Methods included from Measured
Methods included from Units::Class
Constructor Details
#initialize(a, op) ⇒ Unary
Returns a new instance of Unary.
499 500 501 502 503 |
# File 'lib/mathviz.rb', line 499 def initialize(a, op) super() @a = term(a) @op = op end |
Instance Method Details
#constant? ⇒ Boolean
Forward to contained value
530 531 532 |
# File 'lib/mathviz.rb', line 530 def constant? @a.constant? end |
#long ⇒ Object
Debugging method; return string of name and value.
506 507 508 509 |
# File 'lib/mathviz.rb', line 506 def long n = @name && (@name + " = ") "(#{n}#{@a} #{@op} = #{to_f})" end |
#to_dot(g) ⇒ Object
Extend Graphviz g with a representation of this object, and incoming connections
512 513 514 515 516 |
# File 'lib/mathviz.rb', line 512 def to_dot(g) super (g[@a.node] >> g[node]) [:arrowhead => :normal, :headlabel => @op.to_s, :labeldistance => '2'] @a.to_dot(g) if (@a.respond_to?(:name) && @a.name.nil?) end |
#to_f ⇒ Object
Apply the operator to create the derived value.
519 520 521 522 |
# File 'lib/mathviz.rb', line 519 def to_f return MathViz::Infinity unless @a.to_f.finite? @a.to_f.__send__(@op) end |
#units ⇒ Object
Forward to contained value
525 526 527 |
# File 'lib/mathviz.rb', line 525 def units @a.units end |