Class: MathViz::Operation::Unary

Inherits:
MathViz::Operation show all
Defined in:
lib/mathviz.rb

Overview

Display and processing for single-value operators

Instance Attribute Summary

Attributes inherited from Term

#name

Instance Method Summary collapse

Methods inherited from MathViz::Operation

#color, #shape, #term

Methods inherited from Term

binop, #color, #data, #label, list_terms, name_terms!, #shape, #style, #to_i, #to_s, unop

Methods included from Measured

#per, #unit, #with_units

Methods included from Units::Class

#included, #new_units

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

Returns:

  • (Boolean)


530
531
532
# File 'lib/mathviz.rb', line 530

def constant?
  @a.constant?
end

#longObject

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_fObject

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

#unitsObject

Forward to contained value



525
526
527
# File 'lib/mathviz.rb', line 525

def units
  @a.units
end