Sha256: bb3c29d9d675a075d4bb2b940b524bd009a246f18d9c1031fc61d0a8e6738c76

Contents?: true

Size: 1017 Bytes

Versions: 3

Compression:

Stored size: 1017 Bytes

Contents

module XsdReader
  class Schema
    include Shared

    def schema
      return self
    end

    def target_namespace
      node && node.attributes['targetNamespace'] ? node.attributes['targetNamespace'].value : nil
    end

    def namespaces
      self.node ? self.node.namespaces : {}
    end

    def targets_namespace?(ns)
      target_namespace == ns || target_namespace == namespaces["xmlns:#{ns}"]
    end

    def imports
      @imports ||= map_children("xs:import")
    end

    def mappable_children(xml_name)
      result = super
      result += import_mappable_children(xml_name) if xml_name != 'xs:import'
      return result.to_a
    end

    def import_mappable_children(xml_name)
      self.imports.map{|import| import.reader.schema.mappable_children(xml_name)}.flatten
    end

    def import_by_namespace(ns)
      aliases = [ns, namespaces["xmlns:#{(ns || '').gsub(/^xmlns\:/, '')}"]].compact
      return imports.find{|import| aliases.include?(import.namespace)}
    end
  end # class Schema
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xsd-reader-0.3.0 lib/xsd_reader/schema.rb
xsd-reader-0.2.0 lib/xsd_reader/schema.rb
xsd-reader-0.1.0 lib/xsd_reader/schema.rb