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



126
127
128
129
130
131
132
# File 'lib/plurimath/html/parse.rb', line 126

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



147
148
149
# File 'lib/plurimath/html/parse.rb', line 147

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

#parse_tag(opts) ⇒ Object



140
141
142
143
144
145
# File 'lib/plurimath/html/parse.rb', line 140

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



134
135
136
137
138
# File 'lib/plurimath/html/parse.rb', line 134

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

  str(string).as(name)
end