Class: ScaffoldParser::Scaffolders::XSD::Parser::Stack
- Inherits:
-
Object
- Object
- ScaffoldParser::Scaffolders::XSD::Parser::Stack
- Includes:
- Singleton
- Defined in:
- lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Stack
constructor
A new instance of Stack.
- #push(value) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Stack
Returns a new instance of Stack.
8 9 10 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/stack.rb', line 8 def initialize @stack = [] end |
Instance Method Details
#clear ⇒ Object
39 40 41 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/stack.rb', line 39 def clear @stack.clear end |
#push(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/stack.rb', line 12 def push(value) similar_classes = @stack.select { |klass| klass.name.start_with? value.name } if similar_classes.any? same_structure_class = similar_classes.find do |kl| kl.namespace == value.namespace && kl.methods == value.methods && kl.inherit_from == value.inherit_from end if same_structure_class same_structure_class else name_base = value.name while @stack.find { |klass| klass.name == value.name } counter ||= 1 value.name = "#{name_base}#{counter += 1}" end @stack.push value value end else @stack.push value value end end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/stack.rb', line 43 def to_a @stack end |