Method: Cpe.parse

Defined in:
lib/cpe.rb

.parse(cpe) ⇒ Object

Parse pre-existing CPE string and return new Cpe object

String parsing is permissive regarding the number of trailing colons and whitespace provided, filling in empty strings if needed.

Raises:

  • (ArgumentError)


93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cpe.rb', line 93

def Cpe.parse cpe
	raise ArgumentError unless cpe.kind_of? String or cpe.kind_of? File
	cpe = cpe.read if cpe.kind_of? File
	cpe = cpe.downcase.chomp
	raise ArgumentError, "CPE malformed" unless /^cpe:\/[hoa]:/.match cpe and !/[\s\n]/.match cpe

	data = Hash.new
	discard, data[:part], data[:vendor], data[:product], data[:version],
	data[:update], data[:edition], data[:language] = cpe.split(/:/, 8)

	return self.new data
end