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
|
# File 'lib/puppet-cleaner/workers/alignfarrow.rb', line 15
def get_params(line)
depth = 1
max = 0
pos = line.position
params = []
loop do
pos += 1
break if depth == 0 || pos >= line.parts.size
case line.parts[pos].name
when :LBRACE
depth += 1
when :RBRACE
depth -= 1
when :FARROW
next if depth != 1
if line.parts[pos - 1].name == :BLANK
name = line.parts[pos - 2]
before = line.parts[pos - 1]
else
name = line.parts[pos - 1]
before = Part.create([:BLANK, {:value => ''}])
line.insert(pos, [before])
pos += 1
end
if line.parts[pos + 1].name == :BLANK
line.parts[pos + 1].value = ' ' if line.parts[pos + 1].value != ' '
else
line.append(pos, Part.create([:BLANK, {:value => ' '}]))
end
max = name.to_s.size if name.to_s.size > max
params << {:name => name, :before => before}
end
end
[max, params]
end
|