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
|
# File 'lib/manifest.rb', line 23
def read(text)
text.split(MANIFEST_SECTION_SEP).reject { |s| s.chomp == "" }.map do |section|
section.split(MANIFEST_LINE_SEP).each { |line| line.length < 72 }.inject([]) { |merged, line|
if line[0] == ' '
merged.last << line[1..-1]
else
merged << line
end
merged
}.map { |line| line.split(/: /) }.inject({}) { |map, (name, values)|
if (values.nil?)
map.merge!(name=>nil)
else
valuesAsHash = {}
nestedList = false
values.split(/,/).inject([]) { |array, att1|
if nestedList
last = array.pop
array << "#{last},#{att1}"
else
array << att1
end
index = 0
if (/.*"$/.match(att1) || /.*";/.match(att1))
nestedList = false
index = $~[0].size
end
if att1[index, att1.size].match(/"/)
nestedList = true
end
array
}.each { |attribute|
optionalAttributes = {}
values = attribute.split(/;/)
value = values.shift
values.each {|attribute|
array = attribute.split(/:?=/)
optionalAttributes.merge!(array.first.strip=>array.last.strip)
}
valuesAsHash.merge!(value=>optionalAttributes)
}
map.merge!(name=>valuesAsHash)
end
}
end
end
|