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, new_registry, #order_names, #validate, validate, #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)


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

def all?
  is_a?(All)
end

#annotation?Boolean

Returns:

  • (Boolean)


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

def annotation?
  is_a?(Annotation)
end

#any?Boolean

Returns:

  • (Boolean)


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

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.



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

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)


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

def attribute?
  is_a?(Attribute)
end

#attribute_group?Boolean

Returns:

  • (Boolean)


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

def attribute_group?
  is_a?(AttributeGroup)
end

#choice?Boolean

Returns:

  • (Boolean)


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

def choice?
  is_a?(Choice)
end

#complex_content?Boolean

Returns:

  • (Boolean)


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

def complex_content?
  is_a?(ComplexContent)
end

#element?Boolean

Returns:

  • (Boolean)


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

def element?
  is_a?(Element)
end

#max_occurrencesObject



92
93
94
95
96
97
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 92

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

  @max_occurs&.to_i || 1
end

#min_occurrencesObject



86
87
88
89
90
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 86

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
26
27
28
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 19

def resolved_element_order
  return nil unless element_order

  filtered = element_order.reject { |e| e.is_a?(Lutaml::Xml::Element) && e.comment? }
  filtered.each_with_object(filtered.dup) do |element, array|
    next delete_deletables(array, element) if deletable?(element)

    update_element_array(array, element)
  end
end

#sequence?Boolean

Returns:

  • (Boolean)


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

def sequence?
  is_a?(Sequence)
end

#simple_content?Boolean

Returns:

  • (Boolean)


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

def simple_content?
  is_a?(SimpleContent)
end

#target_prefixObject



99
100
101
# File 'lib/lutaml/xml/schema/xsd/base.rb', line 99

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



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

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