Class: XsdReader::Import

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/xsd_reader/import.rb

Instance Attribute Summary

Attributes included from Shared

#options

Instance Method Summary collapse

Methods included from Shared

#[], #all_elements, #attributes, #base, #base_name, #base_namespace, #child_elements?, #choices, #class_for, #complex_content, #complex_contents, #complex_type, #complex_types, #direct_elements, #elements, #extension, #extensions, #initialize, #linked_complex_type, #linked_simple_type, #logger, #map_children, #mappable_children, #name, #name_local, #name_referenced, #node, #node_to_object, #nodes, #object_by_name, #ordered_elements, #parent, #prepend_namespace, #ref, #referenced_element, #schema, #schema_for_namespace, #schema_namespace_prefix, #sequences, #simple_content, #simple_contents, #simple_types, #type, #type_name, #type_namespace

Instance Method Details

#downloadObject



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

def download
  @download ||= download_uri(self.uri)
end

#download_pathObject



37
38
39
40
41
42
# File 'lib/xsd_reader/import.rb', line 37

def download_path
  # we need the parent XSD's path
  return nil if options[:xsd_file].nil?
  parent_path = File.dirname(options[:xsd_file])
  File.join(parent_path, File.basename(schema_location))
end

#local_xmlObject



44
45
46
# File 'lib/xsd_reader/import.rb', line 44

def local_xml
  File.file?(download_path) ? File.read(download_path) : download
end

#namespaceObject



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

def namespace
  node.attributes['namespace'] ? node.attributes['namespace'].value : nil
end

#readerObject



15
16
17
18
19
20
21
22
23
# File 'lib/xsd_reader/import.rb', line 15

def reader
  return @reader || options[:reader] if @reader || options[:reader]
  if download_path
    File.write(download_path, download) if !File.file?(download_path)
    return @reader = XsdReader::XML.new(:xsd_file => download_path)
  end

  return @reader = XsdReader::XML.new(:xsd_xml => download) 
end

#schema_locationObject



11
12
13
# File 'lib/xsd_reader/import.rb', line 11

def schema_location
  node.attributes['schemaLocation'] ? node.attributes['schemaLocation'].value : nil
end

#uriObject



25
26
27
28
29
30
31
# File 'lib/xsd_reader/import.rb', line 25

def uri
  if namespace =~ /\.xsd$/
    namespace
  else
    namespace.gsub(/#{File.basename(schema_location, '.*')}$/, '').to_s + schema_location
  end
end