organize_files 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 887c429ab0830c0802a3132a6d5a649359ffde0d35fb424e252b148b44ae8544
4
+ data.tar.gz: 47b46adcfcbfc75df4ab50d2d15887c126945acfaa3795af86549a5217faba3a
5
+ SHA512:
6
+ metadata.gz: e7f3aa76053ee5c09678d7a2fe1803a9dc1e35bb29e7a0395967977c4ba9b15d01b5e8c80452dad81191c4e1ff167feba42d9b6813a7ea770910ff329dea6bc9
7
+ data.tar.gz: 9df0579e39c59acdcca2d28fefdc6d0dfca7fffeee6227e0bd2fbe5b85c749af2bcd9cce02317844a908246ac561c15a4e328b6c7d686f04a7f96c85a17e48da
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,78 @@
1
+ Contributing Guidelines
2
+
3
+ # Contributing Guidelines
4
+
5
+ Thank you for considering contributing to the `file_organizer` gem! We welcome contributions of all kinds, from bug reports and feature requests to documentation improvements and code contributions. Please read the following guidelines to help us maintain a high standard for the project and to make the contribution process smooth for everyone involved.
6
+
7
+ ## How to Contribute
8
+
9
+ ### 1. Reporting Issues
10
+ - Search the [issue tracker](https://github.com/mayankagnihotri7/file-organizer/issues) to check if the issue has already been reported.
11
+ - If the issue hasn’t been reported, [open a new issue](https://github.com/mayankagnihotri7/file-organizer/issues/new).
12
+ - Provide a clear and descriptive title.
13
+ - Include steps to reproduce the issue, expected results, and actual results.
14
+ - Add screenshots or error messages if applicable.
15
+
16
+ ### 2. Suggesting Features
17
+ - Before suggesting a new feature, check the [issue tracker](https://github.com/mayankagnihotri7/file-organizer/issues) to see if someone else has already suggested it.
18
+ - If not, [open a new issue](https://github.com/mayankagnihotri7/file-organizer/issues/new) and describe the feature you’d like to see.
19
+ - Explain why the feature is useful.
20
+ - Provide details about how it might work.
21
+
22
+ ### 3. Contributing Code
23
+ - Fork the repository and clone your fork locally.
24
+ - Create a new branch for your changes: `git checkout -b feature/your-feature-name`.
25
+ - Follow the [Code of Conduct](#code-of-conduct).
26
+ - Make sure your code adheres to the project’s coding standards:
27
+ - Follow Ruby’s community guidelines and conventions.
28
+ - Use meaningful commit messages.
29
+ - Run tests locally to ensure your changes don’t break existing functionality.
30
+ - Open a pull request (PR) and provide a detailed description of your changes.
31
+
32
+ ### 4. Writing Documentation
33
+ - Review the existing documentation to understand the style and structure.
34
+ - Update relevant sections to reflect your changes.
35
+ - If creating entirely new documentation, ensure it is concise and clear.
36
+
37
+ ### 5. Reviewing Pull Requests
38
+ - Be respectful and constructive.
39
+ - Provide actionable feedback.
40
+
41
+ ## Code Standards
42
+ - Use 2 spaces for indentation.
43
+ - Write descriptive method names.
44
+ - Follow the principle of single responsibility for methods and classes.
45
+ - Add comments for complex logic.
46
+ - Write tests for new features or changes using RSpec.
47
+
48
+ ---
49
+
50
+ # Code of Conduct
51
+
52
+ ## Our Pledge
53
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
54
+
55
+ ## Our Standards
56
+
57
+ Examples of behavior that contributes to creating a positive environment include:
58
+ - Using welcoming and inclusive language.
59
+ - Being respectful of differing viewpoints and experiences.
60
+ - Gracefully accepting constructive criticism.
61
+ - Focusing on what is best for the community.
62
+ - Showing empathy towards other community members.
63
+
64
+ Examples of unacceptable behavior include:
65
+ - The use of sexualized language or imagery and unwelcome sexual attention or advances.
66
+ - Trolling, insulting/derogatory comments, and personal or political attacks.
67
+ - Public or private harassment.
68
+ - Publishing others’ private information, such as a physical or electronic address, without explicit permission.
69
+ - Other conduct which could reasonably be considered inappropriate in a professional setting.
70
+
71
+ ## Our Responsibilities
72
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
73
+
74
+ ## Enforcement
75
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
76
+
77
+ ## Attribution
78
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 File Organizer team, Mayank Agnihotri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # OrganizeFiles
2
+
3
+ This gem provides `Organize Files` integration for Ruby and allows to organize files in your system into their respective folders.
4
+
5
+ ## Getting started
6
+
7
+ - Install the gem
8
+ `gem install organize_files`
9
+ - Enter the directory you want to sort the files in.
10
+ `organize_files '/path/to/file'`
11
+
12
+ ### Requirements
13
+
14
+ This gem requires Ruby 3.0+.
15
+
16
+ ## Contributing
17
+ Please see [CONTRIBUTING.md](CONTRIBUTING.md)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrganizeFiles
4
+ # file_handler.rb
5
+ class FileHandler
6
+ def initialize(directory)
7
+ @directory = directory
8
+ end
9
+
10
+ def scan_files
11
+ Dir.entries(@directory).reject { |file| file.starts_with?('.') }
12
+ end
13
+
14
+ def move_file(file, category)
15
+ destination = File.join(@destination, category)
16
+
17
+ Dir.mkdir(destination) unless Dir.exist?(destination)
18
+ FileUtils.mv(file, destination)
19
+ end
20
+
21
+ def remove_empty_folders
22
+ Dir.entries(@directory).each do |file|
23
+ path = File.join(@directory, file)
24
+
25
+ Dir.rmdir(path) if Dir.empty?(path)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrganizeFiles
4
+ # file_sorter.rb
5
+ class FileOrder
6
+ TYPES = {
7
+ images: ['.jpg', '.jpeg', '.png', '.gif'],
8
+ documents: ['.pdf', '.docx', '.txt', '.md'],
9
+ audio: ['.mp3', '.wav', '.flac'],
10
+ videos: ['.mp4', '.mkv', '.avi'],
11
+ archives: ['.zip', '.tar', '.rar', '.gz']
12
+ }.freeze
13
+
14
+ def initialize(file)
15
+ @file = file
16
+ end
17
+
18
+ def categorize
19
+ file_ext = File.extname(file)
20
+ category = TYPES.find { |_key, exts| exts.include?(file_ext) }
21
+
22
+ case category
23
+ when :images then 'Pictures'
24
+ when :documents then 'Documents'
25
+ when :audio then 'Music'
26
+ when :videos then 'Videos'
27
+ else
28
+ 'Archives'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'file_handler'
4
+ require_relative 'file_order'
5
+
6
+ module OrganizeFiles
7
+ # organizer.rb
8
+ class Organizer
9
+ attr_reader :directory, :types, :new_folder, :new_path
10
+
11
+ def initialize(directory)
12
+ @directory = directory
13
+ @file_handler = FileHandler.new(directory)
14
+ end
15
+
16
+ def organize
17
+ @file_handler.scan_files.each do |file|
18
+ categorize_file = OrganizeFiles::FileOrder.new(file).categorize
19
+
20
+ @file_handler.move_file(file, categorize_file)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrganizeFiles
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'organize_files/orgnizer'
4
+
5
+ organizer = OrganizeFiles::Organizer.new(ARGV[0])
6
+ organizer.organize
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/organize_files/version', __dir__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'organize_files'
7
+ s.authors = ['Mayank Agnihotri']
8
+ s.version = OrganizeFiles::VERSION
9
+ s.files = Dir['README.md', 'LICENSE', 'CHANGELOG.md', 'lib/**/*.rb', 'lib/**/*.rake', 'organize_files.gemspec',
10
+ '.github/*.md', 'Gemfile', 'Rakefile', 'CONTRIBUTING.md']
11
+ s.licenses = ['MIT']
12
+ s.summary = 'Organize files into their own separate folders'
13
+ s.platform = Gem::Platform::RUBY
14
+ s.required_ruby_version = '>= 3.1.4'
15
+ s.extra_rdoc_files = ['README.md']
16
+ s.add_development_dependency 'rubocop', '~> 1.68'
17
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: organize_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mayank Agnihotri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.68'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.68'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.md
33
+ files:
34
+ - CONTRIBUTING.md
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - lib/organize_files.rb
39
+ - lib/organize_files/file_handler.rb
40
+ - lib/organize_files/file_sorter.rb
41
+ - lib/organize_files/organizer.rb
42
+ - lib/organize_files/version.rb
43
+ - organize_files.gemspec
44
+ homepage:
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.1.4
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.3.26
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Organize files into their own separate folders
67
+ test_files: []