forked from kaityo256/yaml_cv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt2yaml.rb
154 lines (139 loc) · 2.55 KB
/
txt2yaml.rb
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require "yaml"
module TXT2YAML
def rest(a, h)
a.each do |v|
b = v.split(/=/)
h[b[0]] = b[1]
end
end
def string(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["value"] = a.shift
rest(a, h)
h
end
def box(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["width"] = a.shift
h["height"] = a.shift
rest(a, h)
h
end
def photo(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["width"] = a.shift
h["height"] = a.shift
h
end
def line(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["dx"] = a.shift
h["dy"] = a.shift
if a.size != 0
rest(a, h)
end
h
end
def lines(a)
h = Hash.new
h["type"] = a.shift
n = a.shift.to_i
points = []
h["points"] = points
points << {"x" => a.shift, "y" => a.shift}
(n - 1).times do
points << {"dx" => a.shift, "dy" => a.shift}
end
rest(a, h)
h
end
def multi_lines(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["dx"] = a.shift
h["dy"] = a.shift
h["num"] = a.shift
h["sx"] = a.shift
h["sy"] = a.shift
h
end
def education_experience(a)
h = Hash.new
h["type"] = a.shift
h["y"] = a.shift
h["year_x"] = a.shift
h["month_x"] = a.shift
h["value_x"] = a.shift
h["dy"] = a.shift
h["caption_x"] = a.shift
h["ijo_x"] = a.shift
rest(a, h)
h
end
def new_page(a)
h = {"type" => "new_page"}
h
end
def history(a)
h = Hash.new
h["type"] = a.shift
h["y"] = a.shift
h["year_x"] = a.shift
h["month_x"] = a.shift
h["value_x"] = a.shift
h["dy"] = a.shift
h["value"] = a.shift
rest(a, h)
h
end
def textbox(a)
h = Hash.new
h["type"] = a.shift
h["x"] = a.shift
h["y"] = a.shift
h["width"] = a.shift
h["height"] = a.shift
h["value"] = a.shift
rest(a, h)
h
end
def convert(filename)
data = []
open(filename) do |f|
while line = f.gets
next if line =~ /^#/
next if line.chomp == ""
a = line.chomp.split(/,/)
d = send(a[0], a)
data.push d if d != nil
end
end
data
end
end
class TXT2YAMLConverter
include TXT2YAML
end
if caller.length == 0
if ARGV.size == 0
puts "usage: input.txt"
exit
end
filename = ARGV[0]
data = TXT2YAMLConverter.new.convert(filename)
YAML.dump(data, $stdout)
end