Class: AsciiMath::AST::SubSup

Inherits:
InnerNode show all
Defined in:
lib/asciimath/ast.rb

Instance Attribute Summary

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from InnerNode

#[], #each, #length

Constructor Details

#initialize(e, sub, sup) ⇒ SubSup

Returns a new instance of SubSup.



184
185
186
187
188
189
# File 'lib/asciimath/ast.rb', line 184

def initialize(e, sub, sup)
  super()
  add(e)
  add(sub || Empty.new)
  add(sup || Empty.new)
end

Instance Method Details

#==(o) ⇒ Object



219
220
221
# File 'lib/asciimath/ast.rb', line 219

def ==(o)
  o.class == self.class && o.base_expression == base_expression && o.sub_expression == sub_expression && o.sup_expression == sup_expression
end

#base_expressionObject



191
192
193
# File 'lib/asciimath/ast.rb', line 191

def base_expression
  child_nodes[0]
end

#sub_expressionObject



195
196
197
198
# File 'lib/asciimath/ast.rb', line 195

def sub_expression
  child = child_nodes[1]
  child.is_a?(Empty) ? nil : child
end

#sup_expressionObject



200
201
202
203
# File 'lib/asciimath/ast.rb', line 200

def sup_expression
  child = child_nodes[2]
  child.is_a?(Empty) ? nil : child
end

#to_sObject



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/asciimath/ast.rb', line 205

def to_s
  s = ""
  s << base_expression.to_s
  sub = sub_expression
  if sub
    s << "_" << sub.to_s
  end
  sup = sup_expression
  if sup
    s << "^" << sup.to_s
  end
  s
end