Class: Plurimath::Omml::Parser
- Inherits:
-
Object
- Object
- Plurimath::Omml::Parser
- Defined in:
- lib/plurimath/omml/parser.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_nodes(nodes) ⇒ Object
Constructor Details
#initialize(text) ⇒ Parser
Returns a new instance of Parser.
9 10 11 |
# File 'lib/plurimath/omml/parser.rb', line 9 def initialize(text) @text = text end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/plurimath/omml/parser.rb', line 7 def text @text end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/plurimath/omml/parser.rb', line 13 def parse nodes = Ox.load(text, strip_namespace: true) @hash = { sequence: parse_nodes(nodes.nodes) } nodes = JSON.parse(@hash.to_json, symbolize_names: true) Math::Formula.new( Transform.new.apply( nodes, ), ) end |
#parse_nodes(nodes) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/plurimath/omml/parser.rb', line 24 def parse_nodes(nodes) nodes.map do |node| if node.is_a?(String) node elsif !node.attributes.empty? { node.name => { attributes: node.attributes, value: parse_nodes(node.nodes), }, } else { node.name => parse_nodes(node.nodes) } end end end |