Sha256: 3e96e507175af3b83997961b47fc4273ac7de0a3f9db43194255425294767fa9
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
require 'nokogiri' # require 'open-uri' module XsdReader class XML attr_reader :options def initialize(_opts = {}) @options = _opts || {} raise "#{self.class.to_s}.new expects a hash parameter" if !@options.is_a?(Hash) end def logger return @logger if @logger @logger ||= options[:logger] || Logger.new(STDOUT) @logger.level = Logger::WARN return @logger end def xsd_from_uri # @xsd_from_uri ||= options[:xsd_uri].nil ? nil : open(options[:xsd_uri]) end def xsd_from_file @xsd_from_file ||= options[:xsd_file].nil? ? nil : File.read(options[:xsd_file]) end def xml @xsd_xml ||= options[:xsd_xml] || options[:xsd_data] || options[:xsd_raw] || xsd_from_file || xsd_from_uri end def doc @doc ||= Nokogiri.XML(xml) end def node nil end def schema_node doc.root.name == 'schema' ? doc.root : nil end def schema @schema ||= Schema.new(self.options.merge(:node => schema_node, :logger => logger)) end # forwards most functions to schema def [](*args) schema[*args] end def elements schema.elements end def imports schema.imports end def simple_types schema.simple_types end def schema_for_namespace(_ns) schema.schema_for_namespace(_ns) end end # class XML end # module XsdReader
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
xsd-reader-0.4.0 | lib/xsd_reader/xml.rb |
xsd-reader-0.3.0 | lib/xsd_reader/xml.rb |
xsd-reader-0.2.0 | lib/xsd_reader/xml.rb |
xsd-reader-0.1.0 | lib/xsd_reader/xml.rb |