lib/junoser/xsd/element.rb in junoser-0.2.2 vs lib/junoser/xsd/element.rb in junoser-0.2.3
- old
+ new
@@ -7,11 +7,11 @@
class Element
include Base
def initialize(xml, options={})
super
- @argument = find_name_element || find_single_simple_type || find_simple_type_attribute
+ @argument = find_name_element || find_type_attribute
end
def config
@config ||= children.map {|child|
case child.name
@@ -20,41 +20,34 @@
when 'simpleType'
'arg'
else
raise "ERROR: unknown element: #{child.name}"
end
- }.compact
+ }
end
def to_s
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join("\n")
-
str = case
- when str.empty? && xml['type']
- l = label ? "#{label} (" : '('
- format(l, format(OFFSET + xml['type'].underscore), ')')
- when str.empty?
+ when content.empty?
format(label)
+ when content =~ /^ *arg$/
+ format("#{label} arg")
+ when label
+ format("#{label} (", content, ')')
else
- l = label ? "#{label} (" : '('
- format(l, str, ')')
+ format('(', content, ')')
end
oneliner? ? "#{str}.as(:oneline)" : str
end
def content
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join("\n")
-
- case
- when str.empty? && xml['type']
- format(OFFSET + xml['type'].underscore)
- when str.empty?
- ''
- else
- str
- end
+ @content ||= if config.empty?
+ xml['type'] ? format(OFFSET + xml['type'].underscore) : ''
+ else
+ config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.join("\n")
+ end
end
private
@@ -81,16 +74,10 @@
def find_name_element
xml.xpath('./xsd:complexType/xsd:sequence/xsd:element[@name="name"]').remove.first
end
- def find_single_simple_type
- simples = xml.xpath('./xsd:simpleType').remove
- raise "ERROR: Element shouldn't have simpleType child and another" if simples.size > 1
- simples.first
- end
-
- def find_simple_type_attribute
+ def find_type_attribute
if xml['type'] =~ /^xsd:.*/
xml.remove_attribute 'type'
'arg'
end
end