Class: RFits::Table

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

Overview

A class representing a generic table extension. Is intended to be abstract.

Direct Known Subclasses

AsciiTable, BinaryTable

Constant Summary

Constants inherited from HDU

HDU::HDU_TYPE_MAP

Instance Attribute Summary collapse

Attributes inherited from HDU

#file, #header

Instance Method Summary collapse

Methods inherited from HDU

#hdu_type, #position, #reset_position

Constructor Details

#initialize(file, extpos, names, formats, extname = nil, units = nil) ⇒ Table

Returns a new instance of Table.



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
# File 'lib/rfits/rfits.rb', line 1261

def initialize(file, extpos, names, formats, extname=nil, units=nil)
  super(file, extpos)
  
  @column_names = names
  @column_formats = formats
  @extname = extname
  @column_units = units
  
  @column_information = ColumnInformationList.new(self)
  @data = TableData.new(self)
end

Instance Attribute Details

#column_informationObject (readonly)

Metadata for each column.



1256
1257
1258
# File 'lib/rfits/rfits.rb', line 1256

def column_information
  @column_information
end

#dataObject (readonly)

Tabular data.



1259
1260
1261
# File 'lib/rfits/rfits.rb', line 1259

def data
  @data
end

Instance Method Details

#to_csvObject

Convert a table to CSV.



1274
1275
1276
1277
1278
1279
1280
1281
1282
# File 'lib/rfits/rfits.rb', line 1274

def to_csv
  col_names = self.column_information.collect{ |ci| ci.name }
  
  buffer = ''
  CSV.generate_row(col_names, col_names.size, buffer)
  buffer << self.data.to_csv
  
  buffer
end

#to_sObject

Convert a table to a string. Currently an alias for Table#to_csv.



1285
1286
1287
# File 'lib/rfits/rfits.rb', line 1285

def to_s
  self.to_csv
end