Class: Plurimath::Html::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/html/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



13
14
15
# File 'lib/plurimath/html/parser.rb', line 13

def initialize(text)
  @text = ::CGI.unescapeHTML(text)
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



11
12
13
# File 'lib/plurimath/html/parser.rb', line 11

def text
  @text
end

Instance Method Details

#parseObject



17
18
19
20
21
22
23
24
# File 'lib/plurimath/html/parser.rb', line 17

def parse
  nodes = Parse.new.parse(text)
  nodes = JSON.parse(nodes.to_json, symbolize_names: true)
  transformed_tree = Transform.new.apply(nodes)
  return transformed_tree if transformed_tree.is_a?(Math::Formula)

  Math::Formula.new(transformed_tree)
end