Class: Rex::Parser::GraphML::Element::Key

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, type, domain) ⇒ Key

Returns a new instance of Key.

Parameters:

  • id (String)

    The document identifier of the attribute described by this element.

  • name (String)

    The name (as used by applications) of the attribute described by this element.

  • type (Symbol)

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

  • domain (Symbol)

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



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_nameObject

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_typeObject

Returns the value of attribute attr_type.



346
347
348
# File 'lib/rex/parser/graphml.rb', line 346

def attr_type
  @attr_type
end

#defaultObject

Returns the value of attribute default.



352
353
354
# File 'lib/rex/parser/graphml.rb', line 352

def default
  @default
end

#domainObject

Returns the value of attribute domain.



349
350
351
# File 'lib/rex/parser/graphml.rb', line 349

def domain
  @domain
end

#idObject

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