Sha256: d2c0fd6e958e2802f5a3f9e3fcfbe2c1002a3ba32ebd0f341e3e7b851c4417ab

Contents?: true

Size: 999 Bytes

Versions: 1

Compression:

Stored size: 999 Bytes

Contents

# frozen_string_literal: true

module OrganizeFiles
  class FileOrder
    def initialize(file, config_file = nil)
      @file = file
      @config_file = config_file || "~/.organize_config.yml"
      @types = load_config
    end

    def categorize
      file_ext = File.extname(@file)
      category = @types.find { |_key, exts| exts.include?(file_ext) }
      return "Miscellaneous" unless category

      category[0].to_s.capitalize
    end

    private

    def load_config
      if File.exist?(@config_file)
        YAML.load_file(@config_file)
      else
        default_config
      end
    end

    def default_config
      {
        pictures: [".jpg", ".jpeg", ".png", ".gif", ".avif"],
        documents: [".pdf", ".docx", ".txt", ".md", ".json", ".csv", ".xls", ".xlsx", ".ppt", ".pptx"],
        music: [".mp3", ".wav", ".flac"],
        videos: [".mp4", ".mkv", ".avi"],
        archives: [".zip", ".tar", ".rar", ".gz", ".7z", ".iso"],
        apks: [".apk"]
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
organize_files-1.1.0 lib/organize_files/file_order.rb