Class: Nmap::XML::CPE::URL

Inherits:
Struct
  • Object
show all
Defined in:
lib/nmap/xml/cpe/url.rb

Overview

Since:

  • 1.0.0

Constant Summary collapse

PARTS =

CPE part codes

Since:

  • 1.0.0

{
  '/a' => :application,
  '/h' => :hardware,
  '/o' => :os
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#editionObject

Returns the value of attribute edition

Returns:

  • (Object)

    the current value of edition



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def edition
  @edition
end

#languageObject

Returns the value of attribute language

Returns:

  • (Object)

    the current value of language



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def language
  @language
end

#partObject

Returns the value of attribute part

Returns:

  • (Object)

    the current value of part



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def part
  @part
end

#productObject

Returns the value of attribute product

Returns:

  • (Object)

    the current value of product



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def product
  @product
end

#updateObject

Returns the value of attribute update

Returns:

  • (Object)

    the current value of update



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def update
  @update
end

#vendorObject

Returns the value of attribute vendor

Returns:

  • (Object)

    the current value of vendor



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



13
14
15
# File 'lib/nmap/xml/cpe/url.rb', line 13

def version
  @version
end

Class Method Details

.parse(url) ⇒ URL

Parses a CPE URL.

Parameters:

  • url (String)

    The raw URL.

Returns:

  • (URL)

    The parsed URL.

Since:

  • 1.0.0



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
# File 'lib/nmap/xml/cpe/url.rb', line 32

def self.parse(url)
  scheme,
    part,
    vendor,
    product,
    version,
    update,
    edition,
    language = url.split(':',8)

  unless scheme == 'cpe'
    raise(ArgumentError,"CPE URLs must begin with 'cpe:'")
  end

  vendor   = vendor.to_sym
  product  = product.to_sym
  language = language.to_sym if language

  return new(
    PARTS[part],
    vendor,
    product,
    version,
    update,
    edition,
    language
  )
end

Instance Method Details

#to_sString

Converts the CPE URL back into a String.

Returns:

  • (String)

    The raw CPE URL.

Since:

  • 1.0.0



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nmap/xml/cpe/url.rb', line 67

def to_s
  'cpe:' + [
    PARTS.invert[part],
    vendor,
    product,
    version,
    update,
    edition,
    language
  ].compact.join(':')
end