Method: Remi::Extractor::SftpFile#most_recent_in_group

Defined in:
lib/remi/extractor/sftp_file.rb

#most_recent_in_group(match_group = @group_by) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/remi/extractor/sftp_file.rb', line 81

def most_recent_in_group(match_group = @group_by)
  entries_with_group = matching_entries.map do |entry|
    match = entry.name.match(match_group)
    next unless match

    group = match.to_a[1..-1]
    { group: group, entry: entry }
  end.compact
  entries_with_group.sort_by! { |e| [e[:group], SortDesc.new(sort_files_by(e[:entry]))] }

  last_group = nil
  entries_with_group.map do |entry|
    next unless entry[:group] != last_group
    last_group = entry[:group]
    entry[:entry]
  end.compact
end