-
Notifications
You must be signed in to change notification settings - Fork 52
/
yaml2txt.rb
128 lines (114 loc) · 2.31 KB
/
yaml2txt.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
require "yaml"
def string(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("value")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def box(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("width")
a.push h.delete("height")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def photo(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("width")
a.push h.delete("height")
puts a.join(",")
end
def line(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("dx")
a.push h.delete("dy")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def lines(h)
a = []
a.push h.delete("type")
points = h.delete("points")
a.push points.size
s = points.shift
a.push s["x"]
a.push s["y"]
points.each do |i|
a.push i["dx"]
a.push i["dy"]
end
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def multi_lines(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("dx")
a.push h.delete("dy")
a.push h.delete("num")
a.push h.delete("sx")
a.push h.delete("sy")
puts a.join(",")
end
def education_experience(h)
a = []
a.push h.delete("type")
a.push h.delete("y")
a.push h.delete("year_x")
a.push h.delete("month_x")
a.push h.delete("value_x")
a.push h.delete("dy")
a.push h.delete("caption_x")
a.push h.delete("ijo_x")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def new_page(h)
puts h.delete("type")
end
def history(h)
a = []
a.push h.delete("type")
a.push h.delete("y")
a.push h.delete("year_x")
a.push h.delete("month_x")
a.push h.delete("value_x")
a.push h.delete("dy")
a.push h.delete("value")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
def textbox(h)
a = []
a.push h.delete("type")
a.push h.delete("x")
a.push h.delete("y")
a.push h.delete("width")
a.push h.delete("height")
a.push h.delete("value")
a = a + h.collect { |k, v| "#{k}=#{v}" }
puts a.join(",")
end
if ARGV.size == 0
puts "usage: input.yaml"
exit
end
filename = ARGV[0]
y = YAML.load_file(filename)
y.each do |i|
send(i["type"], i)
end