| 12345678910111213141516171819202122232425262728293031323334 |
- module Fotos
- class SourceDirectory
- Image = Data.define(:dir_name, :file_name, :file_path, :thumbnail_name, :thumbnail_path)
- def initialize(path)
- @path = path
- end
- attr_reader :path
- #TODO: Filter out non image subdirecories
- def subdirectories
- Dir.glob("#{@path}/*").map {|d| d.split('/').last}
- end
- def dates
- subdirectories.map do |d|
- Date.strptime(d, DATE_FORMAT)
- rescue Date::Error
- next
- end.compact
- end
- def files_by_date
- result = {}
- dates.each do |date|
- dir_name = date.strftime(DATE_FORMAT)
- files = Dir.glob(File.join(@path, dir_name, "*"))
- result[date] = files.map { |path| Fotos::Asset.new(path) }
- end
- return result
- end
- end
- end
|