Class: RFits::Table
Overview
A class representing a generic table extension. Is intended to be abstract.
Direct Known Subclasses
Constant Summary
Constants inherited from HDU
Instance Attribute Summary collapse
-
#column_information ⇒ Object
readonly
Metadata for each column.
-
#data ⇒ Object
readonly
Tabular data.
Attributes inherited from HDU
Instance Method Summary collapse
-
#initialize(file, extpos, names, formats, extname = nil, units = nil) ⇒ Table
constructor
A new instance of Table.
-
#to_csv ⇒ Object
Convert a table to CSV.
-
#to_s ⇒ Object
Convert a table to a string.
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_information ⇒ Object (readonly)
Metadata for each column.
1256 1257 1258 |
# File 'lib/rfits/rfits.rb', line 1256 def column_information @column_information end |
#data ⇒ Object (readonly)
Tabular data.
1259 1260 1261 |
# File 'lib/rfits/rfits.rb', line 1259 def data @data end |
Instance Method Details
#to_csv ⇒ Object
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_s ⇒ Object
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 |