Class: AstroSubframeOrganizer::FileSet
- Inherits:
-
Object
- Object
- AstroSubframeOrganizer::FileSet
- Includes:
- Enumerable
- Defined in:
- lib/astro_subframe_organizer/file_set.rb
Overview
Value object representing a set of files that belong together based on type and metadata.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
-
.from_files(files, type:) ⇒ Object
Factory method to create list of FileSet instances from a list of FileMetadata objects, grouping them by type and relevant metadata.
- .new_group?(first, second) ⇒ Boolean
Instance Method Summary collapse
- #all_unmoved? ⇒ Boolean
- #already_moved? ⇒ Boolean
- #any_unmoved? ⇒ Boolean
- #apply_camera!(camera) ⇒ Object
- #apply_filter!(filter) ⇒ Object
- #apply_telescope!(telescope) ⇒ Object
- #camera ⇒ Object
- #camera_candidates ⇒ Object
- #current_dir ⇒ Object
- #each ⇒ Object
- #filter ⇒ Object
- #filter_candidates ⇒ Object
-
#initialize(files) ⇒ FileSet
constructor
A new instance of FileSet.
- #mark_dark_flat! ⇒ Object
- #maybe_flat_dark? ⇒ Boolean
- #name ⇒ Object
- #size ⇒ Object
- #telescope ⇒ Object
- #telescope_candidates ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(files) ⇒ FileSet
Returns a new instance of FileSet.
10 11 12 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 10 def initialize(files) @files = files end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 8 def files @files end |
Class Method Details
.from_files(files, type:) ⇒ Object
Factory method to create list of FileSet instances from a list of FileMetadata objects, grouping them by type and relevant metadata.
16 17 18 19 20 21 22 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 16 def self.from_files(files, type:) files.select { |file| file.type == type } # Normalize path for sorting: unified separators and consistent case (for Windows) .sort_by { |file| [File.dirname(file.path).tr('\\', '/').downcase, file.filename.downcase] } .slice_when { |a, b| new_group?(a, b) } .map { |group| new(group) } end |
.new_group?(first, second) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 24 def self.new_group?(first, second) first.image_index.to_i > second.image_index.to_i || first.camera != second.camera || first.telescope != second.telescope || first.filter != second.filter end |
Instance Method Details
#all_unmoved? ⇒ Boolean
55 56 57 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 55 def all_unmoved? files.all? { |file| file.path != file.target_path } end |
#already_moved? ⇒ Boolean
51 52 53 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 51 def already_moved? files.all?(&:already_moved?) end |
#any_unmoved? ⇒ Boolean
59 60 61 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 59 def any_unmoved? files.any? { |file| file.path != file.target_path } end |
#apply_camera!(camera) ⇒ Object
71 72 73 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 71 def apply_camera!(camera) files.each { |file| file.camera = camera } end |
#apply_filter!(filter) ⇒ Object
95 96 97 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 95 def apply_filter!(filter) files.each { |file| file.filter = filter } end |
#apply_telescope!(telescope) ⇒ Object
83 84 85 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 83 def apply_telescope!(telescope) files.each { |file| file.telescope = telescope } end |
#camera ⇒ Object
67 68 69 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 67 def camera camera_candidates.one? ? camera_candidates.first : nil end |
#camera_candidates ⇒ Object
63 64 65 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 63 def camera_candidates files.filter_map(&:camera).uniq end |
#current_dir ⇒ Object
47 48 49 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 47 def current_dir files.first.current_dir end |
#each ⇒ Object
35 36 37 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 35 def each(&) @files.each(&) end |
#filter ⇒ Object
91 92 93 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 91 def filter filter_candidates.one? ? filter_candidates.first : nil end |
#filter_candidates ⇒ Object
87 88 89 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 87 def filter_candidates files.filter_map(&:filter).uniq end |
#mark_dark_flat! ⇒ Object
103 104 105 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 103 def mark_dark_flat! files.each { |file| file.dark_flat = true } end |
#maybe_flat_dark? ⇒ Boolean
99 100 101 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 99 def maybe_flat_dark? files.all?(&:maybe_flat_dark?) end |
#name ⇒ Object
31 32 33 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 31 def name "#{type} set #{files.first.filename}..#{files.last.filename}" end |
#size ⇒ Object
39 40 41 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 39 def size @files.size end |
#telescope ⇒ Object
79 80 81 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 79 def telescope telescope_candidates.one? ? telescope_candidates.first : nil end |
#telescope_candidates ⇒ Object
75 76 77 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 75 def telescope_candidates files.filter_map(&:telescope).uniq end |
#type ⇒ Object
43 44 45 |
# File 'lib/astro_subframe_organizer/file_set.rb', line 43 def type files.first.type end |