-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPDX_parser.rb
44 lines (39 loc) · 961 Bytes
/
SPDX_parser.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
class SPDXParser
attr_reader :context, :tag, :value
def initialize(file)
@spdxfile = file
@context = 'document creation'
end
def parse
@spdxfile.gets
return nil if $_.nil?
# p $_
item = /(?<tag>[A-Za-z0-9]+):[ \t](?<value>.*)/.match($_)
while item.nil?
@spdxfile.gets
# p $_
return nil if $_.nil?
item = /(?<tag>[A-Za-z0-9]+):[ \t](?<value>.*)/.match($_)
end
@tag = item[:tag]
case @tag
when 'PackageName'
@context = 'package'
when 'FileName'
@context = 'file'
when 'SnippetSPDXID'
@context = 'snippet'
when 'LicenseID'
@context = 'none'
end
@value = item[:value]
if item[:value].start_with?('<text>')
unless item[:value].end_with?('</text>')
@value += "\n" if @value.length > 6
@value += $_ until @spdxfile.gets.end_with?("</text>\n")
@value = @value.chomp + $_.chomp
end
end
$_
end
end