Class: RFits::ColumnInformationList
- Inherits:
-
Object
- Object
- RFits::ColumnInformationList
- Includes:
- Enumerable
- Defined in:
- lib/rfits/rfits.rb
Overview
A list of ColumnInformation objects representing the set of column definitions. Behaves much like an array.
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
The table the columns belong to.
Instance Method Summary collapse
-
#<<(options) ⇒ Object
Append a new column to the table.
-
#[](i) ⇒ Object
Retrieve the ith column’s information.
-
#[]=(i, options) ⇒ Object
Insert a column into the ith position.
-
#delete(i) ⇒ Object
Delete the ith column.
-
#each ⇒ Object
Iterate through each ColumnInformation object.
-
#initialize(table) ⇒ ColumnInformationList
constructor
Create a list of ColumnInformation from the specified table.
-
#size ⇒ Object
The number of columns in the table.
Constructor Details
#initialize(table) ⇒ ColumnInformationList
Create a list of ColumnInformation from the specified table.
cil = ColumnInformationList.new(table)
1184 1185 1186 |
# File 'lib/rfits/rfits.rb', line 1184 def initialize(table) @table = table end |
Instance Attribute Details
#table ⇒ Object (readonly)
The table the columns belong to.
1180 1181 1182 |
# File 'lib/rfits/rfits.rb', line 1180 def table @table end |
Instance Method Details
#<<(options) ⇒ Object
Append a new column to the table. See ColumnInformationList#[]= for details on what “options” can look like.
cil << {:name => 'new_column_1', :format => 'A10'}
cil << [{:name => 'new_column_1', :format => 'A10'}, {:name => 'new_column_2', :format => 'I'}]
1234 1235 1236 |
# File 'lib/rfits/rfits.rb', line 1234 def <<() self[self.size] = end |
#[](i) ⇒ Object
Retrieve the ith column’s information.
cil[1] # the second column's information
1190 1191 1192 1193 |
# File 'lib/rfits/rfits.rb', line 1190 def [](i) self.table.reset_position ColumnInformation.new(self.table, i) end |
#[]=(i, options) ⇒ Object
Insert a column into the ith position. “options” is a hash with two keys:
- :name
-
the name of the column
- :format
-
the format of the column as explained in the cfitsio documentation
You can also insert multiple columns at the same time by passing an array of hashes of the format explained above.
cil[1] = {:name => 'new_column_1', :format => 'A10'}
cil[1] = [{:name => 'new_column_1', :format => 'A10'}, {:name => 'new_column_2', :format => 'I'}]
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
# File 'lib/rfits/rfits.rb', line 1205 def []=(i, ) self.table.reset_position names = [] formats = [] if .is_a?(Array) .each do |spec| names << spec[:name] formats << spec[:format] end else names = [[:name]] formats = [[:format]] end IO::Proxy.fits_insert_cols(self.table.file.io, i+1, names.size, names, formats) end |
#delete(i) ⇒ Object
Delete the ith column.
cil.delete(1) # delete the second column
1240 1241 1242 1243 |
# File 'lib/rfits/rfits.rb', line 1240 def delete(i) self.table.reset_position IO::Proxy.fits_delete_col(self.table.file.io, i+1) end |
#each ⇒ Object
Iterate through each ColumnInformation object.
1224 1225 1226 1227 1228 |
# File 'lib/rfits/rfits.rb', line 1224 def each (0...self.size).each do |i| yield self[i] end end |
#size ⇒ Object
The number of columns in the table.
cil.size # 4
1247 1248 1249 1250 |
# File 'lib/rfits/rfits.rb', line 1247 def size self.table.reset_position IO::Proxy.fits_get_num_cols(self.table.file.io) end |