Method: Ritex::MathML.generate

Defined in:
lib/ritex/mathml/entities.rb

.generate(element, opts, hash = {}, array = []) ⇒ Object

Generate a hash table of entities from a shorthand version involving a hash table and an array.

element

the HTML element to wrap the entities with

opts

arguments to the opening HTML element



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/ritex/mathml/entities.rb', line 532

def generate(element, opts, hash={}, array=[])
  ret = {}

  endt = "</#{element}>"
  startt =
    unless opts.nil? || opts.empty?
      "<#{element} #{opts}>"
    else
      "<#{element}>"
    end

  array.each do |e|
    if Array === e
      e.each { |i| ret[i] = "#{startt}&#{e.last};#{endt}" }
    else
      ret[e] = "#{startt}&#{e};#{endt}"
    end
  end

  hash.each do |e, v|
    if Array === e
      e.each { |i| ret[i] = "#{startt}&#{v};#{endt}" }
    else
      ret[e] = "#{startt}&#{v};#{endt}"
    end
  end
    
  ret
end