Class: RFits::ColumnInformation
- Inherits:
-
Object
- Object
- RFits::ColumnInformation
- Defined in:
- lib/rfits/rfits.rb
Overview
A class that encapsulates knowledge about the name and type of a column in a table.
Constant Summary collapse
- COLUMN_TYPE_MAP =
{ IO::Proxy::TBIT => :bit, IO::Proxy::TBYTE => :byte, IO::Proxy::TLOGICAL => :logical, IO::Proxy::TSTRING => :string, IO::Proxy::TSHORT => :short, IO::Proxy::TLONG => :long, IO::Proxy::TFLOAT => :float, IO::Proxy::TDOUBLE => :double, IO::Proxy::TCOMPLEX => :complex, IO::Proxy::TDBLCOMPLEX => :dblcomplex }
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
The position of the column in the table.
-
#table ⇒ Object
readonly
The table the column belongs to.
Instance Method Summary collapse
-
#data_type(as_int = false) ⇒ Object
The data type of the column.
-
#dim(maxdim = 1) ⇒ Object
The number of dimensions of the column.
-
#display_width ⇒ Object
The display width (i.e. the width of the column if it were to be converted into it’s string representation).
-
#initialize(table, position) ⇒ ColumnInformation
constructor
Create a new ColumnInformation object on the specified table (of type AsciiTable or BinaryTable) at the specified location (a zero-based index).
-
#name ⇒ Object
The name of the column.
-
#naxes(*args) ⇒ Object
An alias for ColumnInformation#size.
-
#naxis(*args) ⇒ Object
An alias for ColumnInformation#dim.
-
#repeat ⇒ Object
The vector repeat count of the column.
-
#size(maxdim = 1) ⇒ Object
The size of the dimensions of the column.
-
#width ⇒ Object
The width, in bytes, of the column.
Constructor Details
#initialize(table, position) ⇒ ColumnInformation
Create a new ColumnInformation object on the specified table (of type AsciiTable or BinaryTable) at the specified location (a zero-based index).
ci = ColumnInformation.new(tbl, 2) # the third column in the table
1094 1095 1096 1097 |
# File 'lib/rfits/rfits.rb', line 1094 def initialize(table, position) @table = table @position = position end |
Instance Attribute Details
#position ⇒ Object (readonly)
The position of the column in the table.
1089 1090 1091 |
# File 'lib/rfits/rfits.rb', line 1089 def position @position end |
#table ⇒ Object (readonly)
The table the column belongs to.
1086 1087 1088 |
# File 'lib/rfits/rfits.rb', line 1086 def table @table end |
Instance Method Details
#data_type(as_int = false) ⇒ Object
The data type of the column. May be one of:
:bit, :byte, :logical, :string, :short, :long, :float, :double, :complex, :dblcomplex
If the data type is unrecognized, an integer corresponding to the cfitsio data type will be returned instead.
ci.data_type # :string
1111 1112 1113 1114 1115 1116 |
# File 'lib/rfits/rfits.rb', line 1111 def data_type(as_int=false) self.table.reset_position type_info = IO::Proxy.fits_get_coltype(self.table.file.io, self.position+1) as_int ? type_info[0] : COLUMN_TYPE_MAP[type_info[0]] || type_info[0] end |
#dim(maxdim = 1) ⇒ Object
The number of dimensions of the column. “maxdim” is the maximum number of dimensions to return and defaults to 1.
ci.dim # 1
1146 1147 1148 1149 1150 1151 |
# File 'lib/rfits/rfits.rb', line 1146 def dim(maxdim=1) self.table.reset_position dim_info = IO::Proxy.fits_read_tdim(self.table.file.io, self.position+1, 1) dim_info[0] end |
#display_width ⇒ Object
The display width (i.e. the width of the column if it were to be converted into it’s string representation).
ci.display_width # 10
1138 1139 1140 1141 |
# File 'lib/rfits/rfits.rb', line 1138 def display_width self.table.reset_position IO::Proxy.fits_get_col_display_width(self.table.file.io, self.position+1) end |
#name ⇒ Object
The name of the column.
ci.name # 'column_3'
1101 1102 1103 1104 |
# File 'lib/rfits/rfits.rb', line 1101 def name self.table.reset_position IO::Proxy.fits_get_colname(self.table.file.io, IO::Proxy::CASEINSEN, "#{self.position + 1}").first end |
#naxes(*args) ⇒ Object
An alias for ColumnInformation#size
1169 1170 1171 |
# File 'lib/rfits/rfits.rb', line 1169 def naxes(*args) self.size(*args) end |
#naxis(*args) ⇒ Object
An alias for ColumnInformation#dim
1154 1155 1156 |
# File 'lib/rfits/rfits.rb', line 1154 def naxis(*args) self.dim(*args) end |
#repeat ⇒ Object
The vector repeat count of the column. An AsciiTable will always have a repeat of 1.
ci.repeat # 10
1120 1121 1122 1123 1124 1125 |
# File 'lib/rfits/rfits.rb', line 1120 def repeat self.table.reset_position type_info = IO::Proxy.fits_get_coltype(self.table.file.io, self.position+1) type_info[1] end |
#size(maxdim = 1) ⇒ Object
The size of the dimensions of the column. “maxdim” is the maximum number of dimensions to return and defaults to 1.
ci.size # [1]
1161 1162 1163 1164 1165 1166 |
# File 'lib/rfits/rfits.rb', line 1161 def size(maxdim=1) self.table.reset_position dim_info = IO::Proxy.fits_read_tdim(self.table.file.io, self.position+1, maxdim) return dim_info[1] end |
#width ⇒ Object
The width, in bytes, of the column.
ci.width # 10
1129 1130 1131 1132 1133 1134 |
# File 'lib/rfits/rfits.rb', line 1129 def width self.table.reset_position type_info = IO::Proxy.fits_get_coltype(self.table.file.io, self.position+1) type_info[2] end |