Class: Optimus::Reader::LogfileParser::ColumnList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(levels = [], cols = []) ⇒ ColumnList

Returns a new instance of ColumnList.



232
233
234
235
236
# File 'lib/log_file_parser.rb', line 232

def initialize(levels = [], cols = [])
  @levels = levels
  @cols = cols
  @name_uses = Hash.new(0)
end

Instance Attribute Details

#levelsObject

Returns the value of attribute levels.



231
232
233
# File 'lib/log_file_parser.rb', line 231

def levels
  @levels
end

Instance Method Details

#namesObject



249
250
251
252
253
# File 'lib/log_file_parser.rb', line 249

def names
  return self.names_with_cols.map { |c| 
    c[0]
  }
end

#names_with_colsObject



255
256
257
258
259
260
261
# File 'lib/log_file_parser.rb', line 255

def names_with_cols
  ncm = sorted_cols.map {|c| [
      (@name_uses[c.name]==1) ? 
        c.name : "#{c.name}[#{@levels[c.level]}]",
      c ]}
  return ncm
end

#sorted_colsObject



263
264
265
266
267
268
269
270
271
# File 'lib/log_file_parser.rb', line 263

def sorted_cols
  cwi = []
  @cols.each_with_index do |col, i|
    cwi << [col, i]
  end
  return cwi.sort_by {|elem| [elem[0].level, elem[1]]}.map {|elem| 
    elem[0]
  }
end

#store(col) ⇒ Object



238
239
240
241
242
243
244
245
246
247
# File 'lib/log_file_parser.rb', line 238

def store(col)
  if (col.level >= @levels.length  or col.level < 1)
    raise IndexError.new(
      "Level #{col.level} must be between 1 and #{@levels.length-1}")
  end
  if not @cols.include?(col)
    @cols << col
    @name_uses[col.name] += 1
  end
end