Class: Lutaml::Xml::Schema::Xsd::Base

Inherits:
Model::Serializable show all
Defined in:
lib/lutaml/xml/schema/xsd/base.rb

Constant Summary collapse

XML_DECLARATION_REGEX =
/<\?xml[^>]+>\s+/
ELEMENT_ORDER_IGNORABLE =
%w[import include].freeze

Constants included from Model::Serialize

Model::Serialize::DEFAULT_VALUE_MAP, Model::Serialize::INTERNAL_ATTRIBUTES, Model::Serialize::LAZY_EMPTY_COLLECTION

Instance Attribute Summary

Attributes included from Model::Serialize

#lutaml_parent, #lutaml_register, #lutaml_root

Instance Method Summary collapse

Methods included from Model::Serialize

#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #initialize, #key_exist?, #key_value, #method_missing, #prepare_instance_format_options, #pretty_print_instance_variables, register_format_mapping_method, register_from_format_method, register_to_format_method, #respond_to_missing?, #to_format, #to_yaml_hash, #using_default?, #using_default_for, #validate_attribute!, #validate_root_mapping!, #value_map, #value_set_for

Methods included from Model::Liquefiable

included, #to_liquid

Methods included from Model::Validation

#format_element_sequences, #order_names, #validate, #validate!, #validate_helper, #validate_sequence!

Methods included from Model::ComparableModel

#already_compared?, #attributes_hash, #calculate_hash, #comparison_key, #eql?, #hash, included, #same_class?

Methods included from Model::Serialize::Builder

#initialize, #mixed_content?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lutaml::Model::Serialize

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 51

def all?
  is_a?(All)
end

#annotation?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 59

def annotation?
  is_a?(Annotation)
end

#any?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 47

def any?
  is_a?(Any)
end

#assign_root!(root = self, seen = nil) ⇒ Object

Propagate the parsed schema root through the XSD object graph so Liquid helpers can resolve cross-object references consistently.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 29

def assign_root!(root = self, seen = nil)
  seen ||= {}.compare_by_identity
  return self if seen[self]

  seen[self] = true
  self.lutaml_root = root

  self.class.attributes&.each_key do |attribute_name|
    assign_root_value!(public_send(attribute_name), root, seen)
  end

  self
end

#attribute?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 63

def attribute?
  is_a?(Attribute)
end

#attribute_group?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 67

def attribute_group?
  is_a?(AttributeGroup)
end

#choice?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 55

def choice?
  is_a?(Choice)
end

#complex_content?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 75

def complex_content?
  is_a?(ComplexContent)
end

#element?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 79

def element?
  is_a?(Element)
end

#max_occurrencesObject



89
90
91
92
93
94
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 89

def max_occurrences
  return unless respond_to?(:max_occurs)
  return "*" if @max_occurs == "unbounded"

  @max_occurs&.to_i || 1
end

#min_occurrencesObject



83
84
85
86
87
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 83

def min_occurrences
  return unless respond_to?(:min_occurs)

  @min_occurs&.to_i || 1
end

#resolved_element_orderObject



19
20
21
22
23
24
25
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 19

def resolved_element_order
  element_order&.each_with_object(element_order.dup) do |element, array|
    next delete_deletables(array, element) if deletable?(element)

    update_element_array(array, element)
  end
end

#sequence?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 43

def sequence?
  is_a?(Sequence)
end

#simple_content?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 71

def simple_content?
  is_a?(SimpleContent)
end

#target_prefixObject



96
97
98
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 96

def target_prefix
  xsd_root&.target_namespace_prefix
end

#to_formatted_xml(except: []) ⇒ Object



13
14
15
16
17
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 13

def to_formatted_xml(except: [])
  Canon.format_xml(
    to_xml(except: except),
  ).gsub(XML_DECLARATION_REGEX, "")
end

#unresolvable_items(array = [], seen = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 100

def unresolvable_items(array = [], seen = nil)
  seen ||= {}.compare_by_identity
  return array if seen[self]

  seen[self] = true
  resolved_element_order&.each do |element|
    if element.respond_to?(:ref) && element.ref
      if resolvable_reference?(element.ref)
        element.referenced_object&.unresolvable_items(array, seen)
      else
        array << element
      end
    elsif element.respond_to?(:unresolvable_items)
      element.unresolvable_items(array, seen)
    end
  end
  array
end