Class: Lutaml::Xsd::DefinitionExtractor

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

Overview

Extracts XSD definitions from schema files Shows actual XSD source code for types, elements, and attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package) ⇒ DefinitionExtractor

Returns a new instance of DefinitionExtractor.

Parameters:



13
14
15
# File 'lib/lutaml/xsd/definition_extractor.rb', line 13

def initialize(package)
  @package = package
end

Instance Attribute Details

#packageObject (readonly)

Returns the value of attribute package.



10
11
12
# File 'lib/lutaml/xsd/definition_extractor.rb', line 10

def package
  @package
end

Instance Method Details

#extract_attribute_definition(qname) ⇒ Hash?

Extract attribute definition

Parameters:

  • qname (String)

    Qualified name (may include @ prefix)

Returns:

  • (Hash, nil)

    Definition info or nil



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/lutaml/xsd/definition_extractor.rb', line 70

def extract_attribute_definition(qname)
  repository = package.load_repository
  # Remove @ prefix if present
  clean_name = qname.sub(/^@/, "")

  attribute_result = find_attribute_in_repository(repository, clean_name)
  return nil unless attribute_result

  schema, attr_obj, schema_file = attribute_result

  extract_definition_from_xsd(
    schema_file,
    attr_obj.name,
    "attribute",
  ).tap do |def_info|
    if def_info
      def_info[:qname] = clean_name
      def_info[:namespace] = schema.target_namespace
      def_info[:category] = "Attribute"
      def_info[:attribute_object] = attr_obj
      def_info[:schema] = schema
    end
  end
end

#extract_element_definition(qname) ⇒ Hash?

Extract element definition

Parameters:

  • qname (String)

    Qualified name

Returns:

  • (Hash, nil)

    Definition info or nil



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lutaml/xsd/definition_extractor.rb', line 45

def extract_element_definition(qname)
  repository = package.load_repository
  element_result = find_element_in_repository(repository, qname)
  return nil unless element_result

  schema, element_obj, schema_file = element_result

  extract_definition_from_xsd(
    schema_file,
    element_obj.name,
    "element",
  ).tap do |def_info|
    if def_info
      def_info[:qname] = qname
      def_info[:namespace] = schema.target_namespace
      def_info[:category] = "Element"
      def_info[:element_object] = element_obj
      def_info[:schema] = schema
    end
  end
end

#extract_type_definition(qname) ⇒ Hash?

Extract type definition

Parameters:

  • qname (String)

    Qualified name (e.g., “gml:PointType” or “PointType”)

Returns:

  • (Hash, nil)

    Definition info or nil



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lutaml/xsd/definition_extractor.rb', line 20

def extract_type_definition(qname)
  repository = package.load_repository
  type_result = find_type_in_repository(repository, qname)
  return nil unless type_result

  schema, type_obj, schema_file = type_result

  extract_definition_from_xsd(
    schema_file,
    type_obj.name,
    type_obj.class.name.split("::").last.downcase,
  ).tap do |def_info|
    if def_info
      def_info[:qname] = qname
      def_info[:namespace] = schema.target_namespace
      def_info[:category] = type_obj.class.name.split("::").last
      def_info[:type_object] = type_obj
      def_info[:schema] = schema
    end
  end
end