Class: Rex::Parser::GraphML::Element::Key
- Inherits:
-
Object
- Object
- Rex::Parser::GraphML::Element::Key
- Defined in:
- lib/rex/parser/graphml.rb
Overview
A key element defines the attributes that may be present in a document. See: graphml.graphdrawing.org/specification/xsd.html#element-key
Constant Summary collapse
- ELEMENT_NAME =
'key'.freeze
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
Returns the value of attribute attr_name.
-
#attr_type ⇒ Object
Returns the value of attribute attr_type.
-
#default ⇒ Object
Returns the value of attribute default.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, name, type, domain) ⇒ Key
constructor
A new instance of Key.
Constructor Details
#initialize(id, name, type, domain) ⇒ Key
Returns a new instance of Key.
302 303 304 305 306 307 308 |
# File 'lib/rex/parser/graphml.rb', line 302 def initialize(id, name, type, domain) @id = id @attr_name = name @attr_type = type @domain = domain # using 'for' would cause an awkward keyword conflict @default = nil end |
Instance Attribute Details
#attr_name ⇒ Object
Returns the value of attribute attr_name.
343 344 345 |
# File 'lib/rex/parser/graphml.rb', line 343 def attr_name @attr_name end |
#attr_type ⇒ Object
Returns the value of attribute attr_type.
346 347 348 |
# File 'lib/rex/parser/graphml.rb', line 346 def attr_type @attr_type end |
#default ⇒ Object
Returns the value of attribute default.
352 353 354 |
# File 'lib/rex/parser/graphml.rb', line 352 def default @default end |
#domain ⇒ Object
Returns the value of attribute domain.
349 350 351 |
# File 'lib/rex/parser/graphml.rb', line 349 def domain @domain end |
#id ⇒ Object
Returns the value of attribute id.
340 341 342 |
# File 'lib/rex/parser/graphml.rb', line 340 def id @id end |
Class Method Details
.from_xml_attributes(xml_attrs) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/rex/parser/graphml.rb', line 310 def self.from_xml_attributes(xml_attrs) id = xml_attrs['id'] raise Error::InvalidAttributeError.new('key', 'id') if id.nil? name = xml_attrs['attr.name'] raise Error::InvalidAttributeError.new('key', 'attr.name') if name.nil? type = xml_attrs['attr.type'] unless %w[boolean int long float double string].include? type raise Error::InvalidAttributeError.new('key', 'attr.type', details: 'must be boolean int long float double or string', missing: type.nil?) end type = type.to_sym domain = xml_attrs['for'] unless %w[graph node edge all].include? domain raise Error::InvalidAttributeError.new('key', 'for', details: 'must be graph node edge or all', missing: domain.nil?) end domain = domain.to_sym new(id, name, type, domain) end |