Class: Optimus::Reader::LogfileParser::Frame

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ Frame

Returns a new instance of Frame.



178
179
180
181
182
183
184
# File 'lib/log_file_parser.rb', line 178

def initialize(parser)
  @level = nil
  @parent = nil
  @children = []
  @data = Hash.new
  @parser = parser
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



177
178
179
# File 'lib/log_file_parser.rb', line 177

def children
  @children
end

#levelObject

Returns the value of attribute level.



175
176
177
# File 'lib/log_file_parser.rb', line 175

def level
  @level
end

#parentObject

Returns the value of attribute parent.



176
177
178
# File 'lib/log_file_parser.rb', line 176

def parent
  @parent
end

Instance Method Details

#[](key) ⇒ Object

Methods to make this behave hashlike. Don’t just delegate to the @data hash; that’s less clear.



202
203
204
# File 'lib/log_file_parser.rb', line 202

def [](key)
  return @data[Column.new(key, @level).to_s]
end

#[]=(key, val) ⇒ Object



206
207
208
# File 'lib/log_file_parser.rb', line 206

def []=(key, val)
  @data[Column.new(key, @level).to_s] = val
end

#eachObject



214
215
216
217
218
# File 'lib/log_file_parser.rb', line 214

def each
  @data.each do |k, v|
    yield k, v
  end
end

#get(col) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/log_file_parser.rb', line 220

def get(col)
  # If the value is supposed to be at our level, return it (nil is OK)
  return @data[col.to_s] if col.level == @level
  # If it could be in our parent, return that.
  return @parent.get(col) if (@parent && col.level < @level)
  # If that's not an option,
  return nil
end

#keysObject



210
211
212
# File 'lib/log_file_parser.rb', line 210

def keys
  @data.keys
end

#leaf?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/log_file_parser.rb', line 196

def leaf?
  @children.empty?
end