Class: MyData::Xsd::Doc
- Inherits:
-
Object
- Object
- MyData::Xsd::Doc
- Defined in:
- lib/my_data/xsd/doc.rb
Constant Summary collapse
- DEFAULT_ATTRS =
{ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance" }.freeze
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
- #attributes ⇒ Object
- #complex_types ⇒ Object
- #elements ⇒ Object
-
#initialize(doc) ⇒ Doc
constructor
A new instance of Doc.
- #inspect ⇒ Object
- #simple_types ⇒ Object
- #target_namespace ⇒ Object
Constructor Details
#initialize(doc) ⇒ Doc
Returns a new instance of Doc.
10 11 12 |
# File 'lib/my_data/xsd/doc.rb', line 10 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/my_data/xsd/doc.rb', line 4 def doc @doc end |
Instance Method Details
#attributes ⇒ Object
21 22 23 24 25 |
# File 'lib/my_data/xsd/doc.rb', line 21 def attributes @attributes ||= DEFAULT_ATTRS .merge(target_namespace_attributes) .merge(namespace_attributes) end |
#complex_types ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
52 53 54 |
# File 'lib/my_data/xsd/doc.rb', line 52 def inspect "<Schema target_namespace: #{target_namespace.to_json}, attributes: #{attributes}>" end |
#simple_types ⇒ Object
46 47 48 49 50 |
# 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 ⇒ Object
14 15 16 17 18 19 |
# 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 |