Class: Rex::Parser::GraphML::MetaAttribute
- Inherits:
-
Object
- Object
- Rex::Parser::GraphML::MetaAttribute
- 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
-
#default ⇒ Object
Returns the value of attribute default.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.from_key(key) ⇒ Object
Create a new instance from a Key element.
Instance Method Summary collapse
-
#convert(value) ⇒ Object
Convert a value to the type specified by this attribute.
-
#initialize(id, name, type, domain: :all, default: nil) ⇒ MetaAttribute
constructor
A new instance of MetaAttribute.
-
#valid_for?(element) ⇒ Boolean
Whether or not the attribute is valid for the specified element.
Constructor Details
#initialize(id, name, type, domain: :all, default: nil) ⇒ MetaAttribute
Returns a new instance of MetaAttribute.
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
#default ⇒ Object
Returns the value of attribute default.
106 107 108 |
# File 'lib/rex/parser/graphml.rb', line 106 def default @default end |
#domain ⇒ Object
Returns the value of attribute domain.
103 104 105 |
# File 'lib/rex/parser/graphml.rb', line 103 def domain @domain end |
#id ⇒ Object
Returns the value of attribute id.
94 95 96 |
# File 'lib/rex/parser/graphml.rb', line 94 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
97 98 99 |
# File 'lib/rex/parser/graphml.rb', line 97 def name @name end |
#type ⇒ Object
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.
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.
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.
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 |