Class: Delphin::ProfileTable

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

Overview

A data table in a TSDB profile.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile, name, schema) ⇒ ProfileTable

Returns a new instance of ProfileTable.



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/delphin.rb', line 236

def initialize(profile, name, schema)
  @profile = profile
  @name = name
  @schema = schema
  # Find the table containing this table.  It may be gzipped.      
  filename = File.join(profile.directory, name)
  gzname = filename + ".gz"
  if File.exist?(filename)
    @filename = filename
    @file = open(filename)
  elsif File.exist?(gzname)
    @filename = gzname
    @file = Zlib::GzipReader.open(gzname)
  else
    raise MissingDataFile.new(@name, @profile)
  end
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



234
235
236
# File 'lib/delphin.rb', line 234

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



234
235
236
# File 'lib/delphin.rb', line 234

def name
  @name
end

#profileObject (readonly)

Returns the value of attribute profile.



234
235
236
# File 'lib/delphin.rb', line 234

def profile
  @profile
end

#schemaObject (readonly)

Returns the value of attribute schema.



234
235
236
# File 'lib/delphin.rb', line 234

def schema
  @schema
end

Instance Method Details

#eachObject

Enumerate the records in this table.



263
264
265
266
267
# File 'lib/delphin.rb', line 263

def each
  @file.each do |line|
    yield @schema.record(line.strip!)
  end
end

#inspectObject



254
255
256
# File 'lib/delphin.rb', line 254

def inspect
  "#{self.class}(#{name}) in #{profile}"
end

#to_sObject



258
259
260
# File 'lib/delphin.rb', line 258

def to_s
  inspect
end