-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved type parsing to the new Type class
accidental benefit: types are now parsed "lazily", which should cut some time from initially parsing the document.
- Loading branch information
Showing
6 changed files
with
105 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Wasabi | ||
class Type | ||
|
||
def initialize(parser, namespace, node) | ||
@parser = parser | ||
@namespace = namespace | ||
@node = node | ||
end | ||
|
||
attr_reader :namespace | ||
|
||
def children | ||
return @children if @children | ||
|
||
case @node.name | ||
when 'element' | ||
first_child = @node.element_children.first | ||
|
||
if first_child && first_child.name == 'complexType' | ||
children = process_type first_child, @node['name'].to_s | ||
end | ||
when 'complexType' | ||
children = process_type @node, @node['name'].to_s | ||
end | ||
|
||
@children = children || [] | ||
end | ||
|
||
def process_type(type, name) | ||
children = [] | ||
|
||
type.xpath("./xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element| | ||
children << { :name => element["name"].to_s, :type => element["type"].to_s } | ||
end | ||
|
||
type.xpath("./xs:complexContent/xs:extension/xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element| | ||
children << { :name => element["name"].to_s, :type => element["type"].to_s } | ||
end | ||
|
||
type.xpath('./xs:complexContent/xs:extension[@base]', 'xs' => Parser::XSD).each do |extension| | ||
base = extension.attribute('base').value.match(/\w+$/).to_s | ||
base_type = @parser.types.fetch(base) { raise "expected to find extension base #{base} in types" } | ||
|
||
children += base_type.children | ||
end | ||
|
||
children | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters