Class: XsdReader::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/xsd_reader/xml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_opts = {}) ⇒ XML



9
10
11
12
# File 'lib/xsd_reader/xml.rb', line 9

def initialize(_opts = {})
  @options = _opts || {}
  raise "#{self.class.to_s}.new expects a hash parameter" if !@options.is_a?(Hash)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/xsd_reader/xml.rb', line 7

def options
  @options
end

Instance Method Details

#[](*args) ⇒ Object

forwards most functions to schema



50
51
52
# File 'lib/xsd_reader/xml.rb', line 50

def [](*args)
  schema[*args]
end

#docObject



33
34
35
# File 'lib/xsd_reader/xml.rb', line 33

def doc
  @doc ||= Nokogiri.XML(xml)
end

#elementsObject



54
55
56
# File 'lib/xsd_reader/xml.rb', line 54

def elements
  schema.elements
end

#importsObject



58
59
60
# File 'lib/xsd_reader/xml.rb', line 58

def imports
  schema.imports
end

#loggerObject



14
15
16
17
18
19
# File 'lib/xsd_reader/xml.rb', line 14

def logger
  return @logger if @logger
  @logger ||= options[:logger] || Logger.new(STDOUT)
  @logger.level = Logger::WARN
  return @logger
end

#nodeObject



37
38
39
# File 'lib/xsd_reader/xml.rb', line 37

def node
  nil
end

#schemaObject



45
46
47
# File 'lib/xsd_reader/xml.rb', line 45

def schema
  @schema ||= Schema.new(self.options.merge(:node => schema_node, :logger => logger))
end

#schema_for_namespace(_ns) ⇒ Object



66
67
68
# File 'lib/xsd_reader/xml.rb', line 66

def schema_for_namespace(_ns)
  schema.schema_for_namespace(_ns)
end

#schema_nodeObject



41
42
43
# File 'lib/xsd_reader/xml.rb', line 41

def schema_node
  doc.root.name == 'schema' ? doc.root : nil
end

#simple_typesObject



62
63
64
# File 'lib/xsd_reader/xml.rb', line 62

def simple_types
  schema.simple_types
end

#xmlObject



29
30
31
# File 'lib/xsd_reader/xml.rb', line 29

def xml
  @xsd_xml ||= options[:xsd_xml] || options[:xsd_data] || options[:xsd_raw] || xsd_from_file || xsd_from_uri
end

#xsd_from_fileObject



25
26
27
# File 'lib/xsd_reader/xml.rb', line 25

def xsd_from_file
  @xsd_from_file ||= options[:xsd_file].nil? ? nil : File.read(options[:xsd_file])
end

#xsd_from_uriObject



21
22
23
# File 'lib/xsd_reader/xml.rb', line 21

def xsd_from_uri
  # @xsd_from_uri ||= options[:xsd_uri].nil ? nil : open(options[:xsd_uri])
end