Class: Plurimath::Html::Parse

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/plurimath/html/parse.rb

Instance Method Summary collapse

Instance Method Details

#array_to_expression(array, name = nil) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/plurimath/html/parse.rb', line 123

def array_to_expression(array, name = nil)
  initial_type = array.first.class
  array.reduce do |expr, tag|
    expr = str_to_expression(expr, name) if expr.is_a?(initial_type)
    expr | str_to_expression(tag, name)
  end
end

#parse_sub_sup_tags(tag) ⇒ Object



144
145
146
# File 'lib/plurimath/html/parse.rb', line 144

def parse_sub_sup_tags(tag)
  str("<#{tag}>") >> sequence.as(:"#{tag}_value") >> str("</#{tag}>")
end

#parse_tag(opts) ⇒ Object



137
138
139
140
141
142
# File 'lib/plurimath/html/parse.rb', line 137

def parse_tag(opts)
  tag = str("<")
  tag = tag >> str("/") if opts == :close
  tag = tag >> match(/\w+/).repeat
  tag >> str(">")
end

#str_to_expression(string, name) ⇒ Object



131
132
133
134
135
# File 'lib/plurimath/html/parse.rb', line 131

def str_to_expression(string, name)
  return str(string) if name.nil?

  str(string).as(name)
end