Class: Latex::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-latex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caption = nil, label = nil) ⇒ Table

Returns a new instance of Table.



8
9
10
11
12
# File 'lib/ruby-latex.rb', line 8

def initialize(caption = nil, label = nil)
    @caption = caption
    @label = label
    @tabulars = []
end

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



5
6
7
# File 'lib/ruby-latex.rb', line 5

def caption
  @caption
end

#labelObject

Returns the value of attribute label.



6
7
8
# File 'lib/ruby-latex.rb', line 6

def label
  @label
end

Instance Method Details

#add_tabular(tabular) ⇒ Object

Raises:

  • (TypeError)


20
21
22
23
24
25
26
# File 'lib/ruby-latex.rb', line 20

def add_tabular(tabular)
    raise TypeError, "No implicit conversion from #{tabular.class} to Latex::Tabular" unless tabular.is_a?(Tabular)
    
    @tabulars << tabular
    
    return self
end

#auto_resizeObject



14
15
16
17
18
# File 'lib/ruby-latex.rb', line 14

def auto_resize
    @resize = true
    
    return self
end

#tabular=(tabular) ⇒ Object



28
29
30
31
32
33
# File 'lib/ruby-latex.rb', line 28

def tabular=(tabular)
    @tabulars.clear
    add_tabular(tabular)
    
    return nil
end

#to_texObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby-latex.rb', line 35

def to_tex
    out = []
    out << "\\begin{table}"
    out << self.caption_string
    @tabulars.each do |tabular|
        out << tabular.to_tex
    end
    out << "\\end{table}"
    
    return out.join("\n")
end