Class: NVD::JSONFeeds::Schema::Configurations::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/nvd/json_feeds/schema/configurations/node.rb

Overview

Represents a value within "nodes".

Constant Summary collapse

OPERATORS =
{
  'OR'  => :OR,
  'AND' => :AND
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator: nil, negate: nil, children: [], cpe_match: []) ⇒ Node

Initializes the node.

Parameters:

  • operator (:OR, :AND, String) (defaults to: nil)
  • negate (Boolean, nil) (defaults to: nil)
  • children (Array<Node>) (defaults to: [])
  • cpe_match (Array<CPE::Match>) (defaults to: [])


40
41
42
43
44
45
46
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 40

def initialize(operator: nil, negate: nil, children: [], cpe_match: [])
  @operator = operator
  @negate   = negate

  @children = children
  @cpe_match = cpe_match
end

Instance Attribute Details

#childrenArray<Node> (readonly)

Returns:



24
25
26
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 24

def children
  @children
end

#cpe_matchArray<CPE::Match> (readonly)

Returns:



27
28
29
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 27

def cpe_match
  @cpe_match
end

#negateBoolean? (readonly)

Returns:

  • (Boolean, nil)


21
22
23
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 21

def negate
  @negate
end

#operator:OR, ... (readonly)

Returns:

  • (:OR, :AND, String)


18
19
20
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 18

def operator
  @operator
end

Class Method Details

.from_json(json) ⇒ Hash{Symbol => Object}

Maps the parsed JSON to a Symbol Hash for #initialize.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The Symbol Hash.

See Also:



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 68

def self.from_json(json)
  {
    operator: if (operator = json['operator'])
                OPERATORS.fetch(operator,operator)
              end,
    negate:   json['negate'],

    children:  Array(json['children']).map(&method(:load)),
    cpe_match: Array(json['cpe_match']).map(&CPE::Match.method(:load))
  }
end

.load(json) ⇒ Node

Loads the node object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Node)

    The node object.



89
90
91
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 89

def self.load(json)
  new(**from_json(json))
end

Instance Method Details

#negate?Boolean

Determines if #negate is true.

Returns:

  • (Boolean)


53
54
55
# File 'lib/nvd/json_feeds/schema/configurations/node.rb', line 53

def negate?
  @negate == true
end