Class: Junoser::Xsd::Element
- Inherits:
-
Object
- Object
- Junoser::Xsd::Element
show all
- Includes:
- Base
- Defined in:
- lib/junoser/xsd/element.rb
Constant Summary
Constants included
from Base
Base::OFFSET
Instance Attribute Summary
Attributes included from Base
#parent, #xml
Instance Method Summary
collapse
Methods included from Base
#children, #inspect, #oneliner?, #root?
Constructor Details
#initialize(xml, options = {}) ⇒ Element
Returns a new instance of Element.
10
11
12
13
|
# File 'lib/junoser/xsd/element.rb', line 10
def initialize(xml, options={})
super
@argument = find_name_element || find_type_attribute
end
|
Instance Method Details
#config ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/junoser/xsd/element.rb', line 15
def config
@config ||= children.map {|child|
case child.name
when 'complexType'
Junoser::Xsd::ComplexType.new(child, depth: @depth+1, parent: self)
when 'simpleType'
Junoser::Xsd::SimpleType.new(child, depth: @depth+1, parent: self)
else
raise "ERROR: unknown element: #{child.name}"
end
}
end
|
#content ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/junoser/xsd/element.rb', line 47
def content
@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
|
#to_s ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/junoser/xsd/element.rb', line 28
def to_s
str = case
when nokeyword? && content.empty?
format('arg')
when nokeyword?
content
when content.empty?
format(label)
when content =~ /\A *arg\z/
format("#{label} arg")
when label
format("#{label} (", content, ')')
else
format('(', content, ')')
end
oneliner? ? "#{str}.as(:oneline)" : str
end
|