Class: LineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlutils/lineparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLineParser

Returns a new instance of LineParser.



17
18
19
20
21
22
# File 'lib/xmlutils/lineparser.rb', line 17

def initialize()
  @ppms = Hash.new
  @dpms = Hash.new
  @dsms = Hash.new

end

Instance Attribute Details

#dpmsObject

Returns the value of attribute dpms.



13
14
15
# File 'lib/xmlutils/lineparser.rb', line 13

def dpms
  @dpms
end

#dsmsObject

Returns the value of attribute dsms.



14
15
16
# File 'lib/xmlutils/lineparser.rb', line 14

def dsms
  @dsms
end

#ppmsObject

Returns the value of attribute ppms.



12
13
14
# File 'lib/xmlutils/lineparser.rb', line 12

def ppms
  @ppms
end

Instance Method Details

#dumpResultsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/xmlutils/lineparser.rb', line 25

def dumpResults()
  puts "PPMs parsed: #{ppms.size}"
  puts "DPMs parsed: #{dpms.size}"
  puts "DSMs parsed: #{dsms.size}"

  puts "--== PPMs ==--".center(79)
  puts
  @ppms.each do |key, val|
    puts "[#{key}] #{val.name}"
#     puts "[ #{key} ] #{val.inspect}"

    #puts "\t\t#{val.inspect}"

  end # do

  puts
  puts

  puts "--== DPMs ==--".center(79)
  puts
  @dpms.each do |key, val|
    puts "[#{key}] #{val.name}"
  end # do

  puts
  puts

  puts "--== DSMs ==--".center(79)
  puts
  @dsms.each do |key, val|
    puts "[#{key}] #{val.name}"
  end # do

  puts
  puts

end

#getAlias(line) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/xmlutils/lineparser.rb', line 59

def getAlias(line)
  outAry = line.scan(/"([^";]*)"/)
  #puts "Get Alias scan result: #{outAry}"

  outp = outAry[0].to_s
  outp.strip!
  #puts "Get Alias final result: #{outp}"

  return outp
end

#parse(filename) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/xmlutils/lineparser.rb', line 69

def parse(filename)
  fh = File.new(filename)

  fh.readlines.each { |line|
      parseLine(line.chomp!)
  }

end

#parseDpm(line) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/xmlutils/lineparser.rb', line 127

def parseDpm(line)
  puts "parse DPM: #{line}" if $DEBUG
  varAlias = getAlias(line)
  parts = line.split

  parts.each {|part| part.strip!}

  if (parts.length < 3)
    puts "*** Invalid DPM line. Less than 3 items. ***"
    return
  end # if parts


  attributes = Hash.new
  attributes["Type"]        = "DPM"
  attributes["ProductType"] = parts[1]
  attributes["DataType"]    = parts[1]
  varName                   = parts[2]

  if (nil == varAlias || varAlias.length < 1)
    varAlias = varName
  end

  attributes["Name"]        = varAlias

  raise "Missing DPM var name: #{attributes}" unless (varName.length > 0)


  #attributes["Type"]       = parts[2]


  @dpms[varAlias] = Dpm.new(varName, attributes)

end

#parseDsm(line) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/xmlutils/lineparser.rb', line 160

def parseDsm(line)
  puts "parse DSM: #{line}" if $DEBUG
  varAlias = getAlias(line)
  parts = line.split

  parts.each {|part| part.strip!}

  if (parts.length < 4)
    puts "*** Invalid DSM line. Less than 4 items. ***"
    return
  end # if parts


  attributes = Hash.new
  attributes["Type"]        = "DSM"
  attributes["ProductType"] = parts[2]
  attributes["DataType"]    = parts[2]
  varName                   = parts[3]

  if (nil == varAlias || varAlias.length < 1)
    varAlias = varName
  end

  attributes["Name"]        = varAlias


  raise "Missing DSM var name: #{attributes}" unless (varName.length > 0)

  #attributes["Type"]       = parts[2]


  @dsms[varAlias] = Dpm.new(varName, attributes)

end

#parseLine(line) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/xmlutils/lineparser.rb', line 79

def parseLine(line)
  line.gsub!(/;/, '')                       # Remove semi-colon terminators

  parts = line.split
  return unless (parts.length > 0)

  case parts[0]
    when 'ppm'
      parsePpm(line)

    when 'dpm'
      parseDpm(line)

    when 'decision'
      parseDsm(line)

    else
      puts "Skipping line: #{line}" if $DEBUG
  end # case

end

#parsePpm(line) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/xmlutils/lineparser.rb', line 99

def parsePpm(line)
  varAlias = getAlias(line)
  parts = line.split

  parts.each {|part| part.strip!}

  if (parts.length < 5)
    puts "*** Invalid PPM line. Less than 5 items. ***"
    return
  end # if parts


  attributes = Hash.new
  attributes["DataType"]  = parts[1]
  attributes["Type"]      = parts[2]
  varName                 = parts[3]

  raise "Missing PPM var name: #{attributes}" unless (varName.length > 0)

  if (nil == varAlias || varAlias.length < 1)
    varAlias = varName
  end

  attributes["Name"]      = varAlias

  @ppms[varAlias] = Ppm.new(varName, attributes)

end