Class: DataModelInterpreter
Instance Method Summary
collapse
Methods inherited from DslContext
bubble, execute, polish_text
Constructor Details
Returns a new instance of DataModelInterpreter.
6
7
8
9
10
11
|
# File 'lib/DataModelInterpreter.rb', line 6
def initialize
@collections = Hash.new
@elements = []
@elementTree = []
@depth=0
end
|
Instance Method Details
#collection(*args) ⇒ Object
55
56
57
|
# File 'lib/DataModelInterpreter.rb', line 55
def collection(*args)
@collections.merge!(args[0])
end
|
#coverage(*args) ⇒ Object
67
68
69
|
# File 'lib/DataModelInterpreter.rb', line 67
def coverage(*args)
createNewElement(args[0]+ "Coverage",nil,true,@elementTree.last,"coverages")
end
|
#createNewElement(name, ctype, coverage, parent, type) ⇒ Object
the type tells us if it is an entity, or coverage, or nil if a simple element
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/DataModelInterpreter.rb', line 27
def createNewElement(name,ctype,coverage,parent,type) e = ElementFactory(name,coverage,parent,type)
@elementTree.last.children.push e if @elementTree.last and @elementTree.length > 0
if ctype and ctype != name
@elements.each do |node|
if node.name == ctype
e.fields = node.fields
e.children = node.children
e.parent = @elementTree.last
end
end
end
@elementTree.push e
end
|
#datamodel(*args) ⇒ Object
–parse - implement the grammar
21
22
|
# File 'lib/DataModelInterpreter.rb', line 21
def datamodel(*args)
end
|
#dumpParsedStructure ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/DataModelInterpreter.rb', line 101
def dumpParsedStructure
@dumpStructure = ""
@elements.each do |e|
if (e.coverage)
@dumpStructure << "#{e.name}:\n"
listChildren(e)
@dumpStructure << "\n"
end
end
puts "#{@dumpStructure}"
end
|
#element(*args) ⇒ Object
59
60
61
|
# File 'lib/DataModelInterpreter.rb', line 59
def element(*args)
createNewElement(args[0],nil,false,@elementTree.last,nil)
end
|
#ElementFactory(name, coverage, parent, type) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/DataModelInterpreter.rb', line 43
def ElementFactory(name,coverage,parent,type)
@elements.each do |node|
if node.name == name
node.parent = parent
return node
end
end
e = Element.new(name,coverage,parent,type)
@elements.push e
return e
end
|
#endcoverage(*args) ⇒ Object
71
72
73
|
# File 'lib/DataModelInterpreter.rb', line 71
def endcoverage(*args)
@elementTree.pop
end
|
#enddatamodel(*args) ⇒ Object
24
25
|
# File 'lib/DataModelInterpreter.rb', line 24
def enddatamodel(*args)
end
|
#endelement(*args) ⇒ Object
63
64
65
|
# File 'lib/DataModelInterpreter.rb', line 63
def endelement(*args)
@elementTree.pop
end
|
#endentity(*args) ⇒ Object
79
80
81
|
# File 'lib/DataModelInterpreter.rb', line 79
def endentity(*args)
@elementTree.pop
end
|
#entity(*args) ⇒ Object
75
76
77
|
# File 'lib/DataModelInterpreter.rb', line 75
def entity(*args)
createNewElement(args[0],nil,true,@elementTree.last,"entities")
end
|
#field(*args) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/DataModelInterpreter.rb', line 83
def field(*args)
if (args[0][:ctype] != nil)
if (@elementTree.last.coverage)
parent = nil
else
parent = @elementTree.last
end
createNewElement(args[0][:name],args[0][:ctype],false,parent,nil)
@elementTree.pop
else
@elementTree.last.fields.push args[0]
end
end
|
#getResult ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/DataModelInterpreter.rb', line 13
def getResult
result = []
result[0] = @elements
result[1] = @collections
result
end
|
#listChildren(e) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/DataModelInterpreter.rb', line 113
def listChildren(e)
@depth = @depth + 1
e.children.each do |c|
str = ""
@depth.times { str << "\t"}
@dumpStructure << "#{str}#{c.name}\n"
c.fields.each do |f|
str = ""
@depth.times { str << "\t\t"}
@dumpStructure << "#{str}field:#{f}\n"
end
listChildren(c)
@depth = @depth - 1
end
end
|