Class: Rex::Parser::GraphML::MetaAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/parser/graphml.rb

Overview

Define a GraphML attribute including its name, data type, default value and where it can be applied.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, type, domain: :all, default: nil) ⇒ MetaAttribute

Returns a new instance of MetaAttribute.

Parameters:

  • id (String)

    The attribute's document identifier.

  • name (String)

    The attribute's name as used by applications.

  • type (Symbol)

    The data type of the attribute, one of either boolean, int, long, float, double or string.

  • domain (Symbol) (defaults to: :all)

    What elements this attribute is valid for, one of either edge, node, graph or all.

  • default (defaults to: nil)

    An optional default value for this attribute.



60
61
62
63
64
65
66
# File 'lib/rex/parser/graphml.rb', line 60

def initialize(id, name, type, domain: :all, default: nil)
  @id = id
  @name = name
  @type = type
  @domain = domain
  @default = default
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



106
107
108
# File 'lib/rex/parser/graphml.rb', line 106

def default
  @default
end

#domainObject

Returns the value of attribute domain.



103
104
105
# File 'lib/rex/parser/graphml.rb', line 103

def domain
  @domain
end

#idObject

Returns the value of attribute id.



94
95
96
# File 'lib/rex/parser/graphml.rb', line 94

def id
  @id
end

#nameObject

Returns the value of attribute name.



97
98
99
# File 'lib/rex/parser/graphml.rb', line 97

def name
  @name
end

#typeObject

Returns the value of attribute type.



100
101
102
# File 'lib/rex/parser/graphml.rb', line 100

def type
  @type
end

Class Method Details

.from_key(key) ⇒ Object

Create a new instance from a Key element.

Parameters:



72
73
74
# File 'lib/rex/parser/graphml.rb', line 72

def self.from_key(key)
  new(key.id, key.attr_name, key.attr_type, domain: key.domain, default: key.default&.value)
end

Instance Method Details

#convert(value) ⇒ Object

Convert a value to the type specified by this attribute.

Parameters:

  • value

    The value to convert.



80
81
82
# File 'lib/rex/parser/graphml.rb', line 80

def convert(value)
  GraphML.convert_attribute(@type, value)
end

#valid_for?(element) ⇒ Boolean

Whether or not the attribute is valid for the specified element.

Parameters:

Returns:

  • (Boolean)


88
89
90
# File 'lib/rex/parser/graphml.rb', line 88

def valid_for?(element)
  @domain == :all || @domain == element.class::ELEMENT_NAME.to_sym
end