summaryrefslogtreecommitdiffstats
path: root/generation/barcodelist.rb
blob: 515403f3846a5567beba04b37c75e98619133023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby -w
# encoding: UTF-8

require "csv"

#csv input "userid,firstname,lastname"

@template = %q{
	\documentclass[a4paper,landscape]{article}
	\usepackage[utf8]{inputenc}
	\usepackage{graphicx}
	\usepackage{longtable}
	\usepackage[top=0.5cm,right=0.5cm,bottom=0.5cm,left=0.5cm,landscape]{geometry}
	\renewcommand{\familydefault}{\sfdefault}
	\title{Barcodelist}
	\author{Kreativitaet trifft Technik}
	\date{\today}
	\begin{document}
		\begin{center}
		\begin{longtable}{|c|c|c|}
			%s	
		\end{longtable}
	\end{center}
	\end{document}}

@line = %q{
	\hline
	%s
	\hline
	%s
	\hline}

@graphics = %q{ \includegraphics{%s} %s}
@name = %q{ %s %s %s}

@csv = CSV.read(ARGV[0])

#generate barcodes
@csv.each{|r| 
	system("barcode -n -E -b 'USER %s' -o '%s.eps' -e 39\n" % [r[0], r[0]])
}

#generate latex
tmp = ""
graphics = ""
name = ""
1.upto(@csv.length){|i|
	le = i % 3 == 0 || i >= @csv.length
	sign = le ? "\\\\" : "&"
	graphics += @graphics % [@csv[i-1][0], sign]
	name += @name % [@csv[i-1][1], @csv[i-1][2], sign]
	if le 
		tmp += @line % [graphics, name] 
		graphics = ""
		name = ""
	end
}
File.open("barcode.latex", "w+"){|f| f.write(@template % tmp)}