Class: Lutaml::Xsd::TypeHierarchyNode

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/type_hierarchy_analyzer.rb

Overview

Value object representing a node in type hierarchy Immutable once created, with ancestors and descendants

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qualified_name, category:, depth: 0) ⇒ TypeHierarchyNode

Returns a new instance of TypeHierarchyNode.



319
320
321
322
323
324
325
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 319

def initialize(qualified_name, category:, depth: 0)
  @qualified_name = qualified_name
  @category = category
  @depth = depth
  @ancestors = []
  @descendants = []
end

Instance Attribute Details

#ancestorsObject (readonly)

Returns the value of attribute ancestors.



317
318
319
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 317

def ancestors
  @ancestors
end

#categoryObject (readonly)

Returns the value of attribute category.



317
318
319
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 317

def category
  @category
end

#depthObject (readonly)

Returns the value of attribute depth.



317
318
319
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 317

def depth
  @depth
end

#descendantsObject (readonly)

Returns the value of attribute descendants.



317
318
319
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 317

def descendants
  @descendants
end

#qualified_nameObject (readonly)

Returns the value of attribute qualified_name.



317
318
319
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 317

def qualified_name
  @qualified_name
end

Instance Method Details

#add_ancestor(node) ⇒ Object

Add an ancestor node (base type)

Parameters:



329
330
331
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 329

def add_ancestor(node)
  @ancestors << node unless @ancestors.include?(node)
end

#add_descendant(node) ⇒ Object

Add a descendant node (derived type)

Parameters:



335
336
337
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 335

def add_descendant(node)
  @descendants << node unless @descendants.include?(node)
end

#to_hHash

Convert to hash for serialization

Returns:

  • (Hash)

    Hash representation



341
342
343
344
345
346
347
348
349
# File 'lib/lutaml/xsd/type_hierarchy_analyzer.rb', line 341

def to_h
  {
    qualified_name: @qualified_name,
    category: @category,
    depth: @depth,
    ancestors: @ancestors.map(&:to_h),
    descendants: @descendants.map(&:to_h),
  }
end