Class: AstroSubframeOrganizer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/astro_subframe_organizer/config.rb

Overview

Configuration management for user-customizable options

Constant Summary collapse

DEFAULT_CONFIG =
{
  'telescopes' => %w[
    RedCat51
    ZhumellZ130
    AperturaAD8
    MeadeDS90
    CanonEFS1855
  ],
  'filters' => %w[
    BaaderMoon
    NBZ
    NoFilter
  ],
  'cameras' => [
    'T7',
    '183MC',
    'ZWO ASI183MC Pro',
    'Canon EOS 1500D',
  ],
  'temperature_tolerance' => 5.0,
  'fits_extensions' => %w[.fit .fits .fts],
  'raw_extensions' => %w[.cr2 .cr3 .nef .arw .orf .raf .dng],
  'exif_tag_mappings' => {
    'temperature' => %i[camera_temperature sensor_temperature ambient_temperature],
    'iso' => %i[iso base_iso],
    'exposure' => %i[exposure_time],
    'model' => %i[model],
    'timestamp' => %i[date_time_original],
  },
  'fits_header_mappings' => {
    'temperature' => %w[CCD-TEMP SET-TEMP TEMP],
    'gain' => %w[GAIN GAINVAL],
    'exposure' => %w[EXPOSURE EXPTIME],
    'filter' => %w[FILTER FILTERNAME],
    'telescope' => %w[TELESCOP],
    'target' => %w[OBJECT TARGET],
    'camera' => %w[INSTRUME],
    'binning' => %w[XBINNING CCDXBIN BINNING],
    'type' => %w[IMAGETYP FRAME],
    'date_obs' => %w[DATE-OBS DATE],
    'rotation' => %w[ROTATANG ANGLE POSANGLE ROTATOR ROTAT OBJCTROT CCDROTSA],
    'iso' => %w[ISO],
  },
  'telescope_ignore_patterns' => [
    'Mount',
    'EQMod',
    'AM5',
    'AM3',
    'RST-135',
    'Star Adventurer',
  ],
}.freeze

Class Method Summary collapse

Class Method Details

.all_camerasObject



100
101
102
# File 'lib/astro_subframe_organizer/config.rb', line 100

def self.all_cameras
  load['cameras']
end

.all_filtersObject



96
97
98
# File 'lib/astro_subframe_organizer/config.rb', line 96

def self.all_filters
  load['filters']
end

.all_telescopesObject



92
93
94
# File 'lib/astro_subframe_organizer/config.rb', line 92

def self.all_telescopes
  load['telescopes']
end

.config_fileObject

Returns the expanded path to the configuration file.



70
71
72
73
# File 'lib/astro_subframe_organizer/config.rb', line 70

def self.config_file
  path = custom_config_file || '~/astro-subframe-organizer-config.yml'
  File.expand_path(path)
end

.create_default_configObject



129
130
131
132
133
134
135
136
137
138
# File 'lib/astro_subframe_organizer/config.rb', line 129

def self.create_default_config
  # Only include basic equipment and settings in the generated template.
  # Advanced mappings and ignore patterns are handled via application defaults
  # unless explicitly overridden by the user.
  template = DEFAULT_CONFIG.slice(
    'telescopes', 'filters', 'cameras', 'temperature_tolerance'
  )

  File.write(config_file, template.to_yaml)
end

.custom_config_fileObject



65
66
67
# File 'lib/astro_subframe_organizer/config.rb', line 65

def self.custom_config_file
  ENV.fetch('ASTRO_SUBFRAME_ORGANIZER_CONFIG', nil)
end

.exif_tag_mappingsObject



116
117
118
# File 'lib/astro_subframe_organizer/config.rb', line 116

def self.exif_tag_mappings
  load['exif_tag_mappings'] || DEFAULT_CONFIG['exif_tag_mappings']
end

.fits_extensionsObject



108
109
110
# File 'lib/astro_subframe_organizer/config.rb', line 108

def self.fits_extensions
  load['fits_extensions'] || DEFAULT_CONFIG['fits_extensions']
end

.fits_header_mappingsObject



120
121
122
# File 'lib/astro_subframe_organizer/config.rb', line 120

def self.fits_header_mappings
  load['fits_header_mappings'] || DEFAULT_CONFIG['fits_header_mappings']
end

.loadObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/astro_subframe_organizer/config.rb', line 75

def self.load
  @load ||=
    if File.exist?(config_file)
      # Normalize path separators for consistent logging/testing across platforms
      AstroSubframeOrganizer.logger.info "Using config file at #{config_file.tr('\\', '/')}"
      DEFAULT_CONFIG.merge(YAML.safe_load_file(config_file, permitted_classes: [Symbol, DateTime]))
    elsif custom_config_file
      AstroSubframeOrganizer.logger.error("Unable to find #{config_file.tr('\\', '/')}. Check path and try again.")
      exit(1)
    else
      AstroSubframeOrganizer.logger.info "Using config file at #{config_file.tr('\\', '/')}"
      DEFAULT_CONFIG
    end
rescue StandardError => e
  AstroSubframeOrganizer.logger.error("Failed to parse #{config_file}: #{e}")
end

.raw_extensionsObject



112
113
114
# File 'lib/astro_subframe_organizer/config.rb', line 112

def self.raw_extensions
  load['raw_extensions'] || DEFAULT_CONFIG['raw_extensions']
end

.telescope_ignore_patternsObject



124
125
126
127
# File 'lib/astro_subframe_organizer/config.rb', line 124

def self.telescope_ignore_patterns
  patterns = load['telescope_ignore_patterns'] || DEFAULT_CONFIG['telescope_ignore_patterns']
  patterns.map { |p| Regexp.new(Regexp.escape(p), Regexp::IGNORECASE) }
end

.temperature_toleranceObject



104
105
106
# File 'lib/astro_subframe_organizer/config.rb', line 104

def self.temperature_tolerance
  load['temperature_tolerance']&.to_f || 5.0
end