| Class | RFits::Header |
| In: |
lib/rfits/rfits.rb
|
| Parent: | Object |
Represents the header keyword information of an HDU. Behaves much like a hash.
| hdu | [R] | The HDU associated with the header. |
Initialize the header. This doesn‘t actually write bytes to file—use Header#create for that.
header = Header.new(hdu)
Retrieve the value of the specified keyword. If include_comment is true, the returned value will be a two-element array with the value as the first element, and the comment as the second. The return type of the value will be determined automatically—this is almost always what you want. However, if necessary, you may specify the type using as, which may be one of: "C" (string), "L" (logical), "I" (integer), "F" (float) or "C" (complex) and the library will try to do the right thing.
puts header['OBJNAME'] # M31 puts header['OBJNAME', true] # ['M31', 'The name of the object'] puts header['BITPIX'] # 8 puts header['BITPIX', false, 'F'] # 8.0
Set the value of the keyword. If keyvalue is an array, the first element of that array is assumed to be the value, and the second the comment. The value may be a: String, boolean, Fixnum, Float or Complex object. Anything else will be serialized using it‘s to_s method and saved as a string.
header['TEST1'] = 123 # set keyword value to 123 header['TEST1'] = [123, 'a test integer'] # set keyword value to 123 with "a test integer" as the comment
Retrieve COMMENT keywords as a string.
puts header.comments # This file is part of the EUVE Science Archive. It contains...
Iterate through each keyword pair in the header. By default, values will be converted to their appropriate types, but this can be overridden by setting typecast to false. Additionally, COMMENT and HISTORY keywords are ignored unless comment_keywords is set to true.
header.each do |name, value, comment|
puts "#{name} = #{value}"
end