Class: Mo2tex::Latex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Latex

Returns a new instance of Latex.



13
14
15
16
17
18
19
# File 'lib/mo2tex/latex.rb', line 13

def initialize(s)
    @total_hours_done = 0
  @school = s
	@header = read_header
	@trailer = read_trailer
	@body = read_body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/mo2tex/latex.rb', line 11

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



11
12
13
# File 'lib/mo2tex/latex.rb', line 11

def header
  @header
end

#schoolObject (readonly)

Returns the value of attribute school.



11
12
13
# File 'lib/mo2tex/latex.rb', line 11

def school
  @school
end

#total_hours_doneObject (readonly)

Returns the value of attribute total_hours_done.



11
12
13
# File 'lib/mo2tex/latex.rb', line 11

def total_hours_done
  @total_hours_done
end

#trailerObject (readonly)

Returns the value of attribute trailer.



11
12
13
# File 'lib/mo2tex/latex.rb', line 11

def trailer
  @trailer
end

Instance Method Details

#generateObject



21
22
23
24
25
# File 'lib/mo2tex/latex.rb', line 21

def generate
	result = self.header
	result += self.body.result(binding)
	result += self.trailer
end

#table_bodyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mo2tex/latex.rb', line 27

def table_body
    result = ''
    head = proc { |title, students| "\\hline\n\\multicolumn{3}{|l|}{\\bfseries #{title}}\\\\\n\\multicolumn{3}{|p{0.9\\textwidth}|}{studenti: #{students}}\\\\\n\\hline\n" }
    tail = proc { |sctot| "\\multicolumn{2}{l}{Totale ore corso:} & \\hfill#{sctot.round.to_i}\\\\\n & & \\\\\n" }
	@total_hours_done, result = self.school.generate(head, tail) do
      |title, nol, ev|
      sprintf("%s & %s--%s & Lezione n.%02d/%02d\\\\\n", ev.dtstart.strftime("%d/%m/%Y"),
                                                         ev.dtstart.strftime("%H:%M"),
                                                         ev.dtend.strftime("%H:%M"),
                                                         ev.lnumber, ev.ltot)
    end
    @total_hours_done = @total_hours_done.round.to_i
    return result
end