Class: Rulex::Tex::Writer

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWriter

Returns a new instance of Writer.



5
6
7
# File 'lib/rulex/tex/writer.rb', line 5

def initialize
  @content = ''
end

Class Method Details

.to_str(item) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rulex/tex/writer.rb', line 9

def self.to_str item
  case item[:type]
  when :command
    str = "\\#{item[:name]}"
    if opts = item[:options]
      str += '[' + opts.join(',') + ']'
    end
    item[:arguments].each do |arg|
      str += "{#{arg}}"
    end
    str += "\n"
  when :text
    res = item[:text]
  when :environment
    str = "\\begin{#{item[:name]}}\n"
    if children = item[:children]
      str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} 
    end
    res = str += "\\end{#{item[:name]}}\n"
  else
    str = ""
    res = str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} if item[:children]
  end
end

Instance Method Details

#import(arr) ⇒ Object



34
35
36
# File 'lib/rulex/tex/writer.rb', line 34

def import arr
  arr.each {|i| @content += Rulex::Tex::Writer.to_str i} if arr
end

#to_sObject Also known as: export



38
39
40
# File 'lib/rulex/tex/writer.rb', line 38

def to_s
  @content
end