Class: Rulex::Tex::Reader

Inherits:
Object show all
Defined in:
lib/rulex/tex/reader.rb

Instance Method Summary collapse

Constructor Details

#initializeReader

Returns a new instance of Reader.



13
14
15
16
# File 'lib/rulex/tex/reader.rb', line 13

def initialize
  @parser = LatexParser.new
  @content = []
end

Instance Method Details

#read(str) ⇒ Array

Takes a string of LaTeX contents, parses it to a Rulex tree, and sets that tree as the Reader’s content

Parameters:

  • str (String)

    the LaTeX contents as a String

Returns:

  • (Array)

    The new content

Raises:

  • (TypeError)


29
30
31
32
33
# File 'lib/rulex/tex/reader.rb', line 29

def read str
  new_content = @parser.parse(str).to_a
  raise TypeError, "content should be an Array" unless new_content and Array === new_content
  @content = new_content
end

#to_aArray Also known as: export

Exports the Reader’s content

Returns:

  • (Array)

    the Reader’s content



20
21
22
# File 'lib/rulex/tex/reader.rb', line 20

def to_a
  @content
end