class MyData::Xsd::Doc
Constants
- DEFAULT_ATTRS
Attributes
doc[R]
Public Class Methods
new(doc)
click to toggle source
# File lib/my_data/xsd/doc.rb, line 10 def initialize(doc) @doc = doc end
Public Instance Methods
attributes()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 21 def attributes @attributes ||= DEFAULT_ATTRS .merge(target_namespace_attributes) .merge(namespace_attributes) end
complex_types()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 40 def complex_types @complex_types ||= doc.xpath("//xs:schema/xs:complexType").map do |node| MyData::Xsd::ComplexType.new(node, namespace: target_namespace) end end
elements()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 27 def elements @elements ||= begin sequence = doc.child.xpath("xs:element/xs:complexType/xs:sequence").first elements = sequence.xpath("xs:element") collection = elements.count == 1 && sequence.attributes["maxOccurs"].present? sequence.xpath("xs:element").map do |element| MyData::Xsd::Element.new(element, force_collection: collection) end end end
inspect()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 52 def inspect "<Schema target_namespace: #{target_namespace.to_json}, attributes: #{attributes}>" end
simple_types()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 46 def simple_types @simple_types ||= doc.xpath("//xs:schema/xs:simpleType").map do |node| MyData::Xsd::Element.new(node, namespace: target_namespace) end end
target_namespace()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 14 def target_namespace return @target_namespace if defined? @target_namespace @target_namespace = (doc.namespaces.find { |_k, v| v == target_namespace_value }.first.split(":").last if target_namespace_value) end
Private Instance Methods
namespace_attributes()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 71 def namespace_attributes @namespace_attributes ||= doc .namespaces .reject { |k, _| k == "xmlns:xs" } .reject { |_, v| v == target_namespace } end
target_namespace_attributes()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 62 def target_namespace_attributes return {} unless target_namespace_value { "xmlns" => target_namespace_value, "xmlns:schema" => "#{target_namespace_value} schemaLocation.xsd" } end
target_namespace_value()
click to toggle source
# File lib/my_data/xsd/doc.rb, line 58 def target_namespace_value doc.child.attributes["targetNamespace"]&.value end