fylorg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/fylorg +4 -0
- data/lib/cli.rb +21 -0
- data/lib/fylorg/confparser.rb +11 -0
- data/lib/fylorg/fileman.rb +34 -0
- data/lib/fylorg/matcher.rb +42 -0
- data/lib/fylorg.rb +23 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a2460b23831f4d8bbe3ef7b7cbfa857fbf1aa5d58d2afadbc24bbb2737761d13
|
4
|
+
data.tar.gz: e4af192d5b232f58304bca743f916b91b29a096b5e6a3a9c2780c13dda502b9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '078a64cb1df18984f3855b54c9d9563e4d0a99f07d8917e1836532633a1738e9c9f21793b0926a0c00e7a1318a308aebf6b2bf0f1fa1aa21cecdf02615e3787b'
|
7
|
+
data.tar.gz: e8df3d915aa62d9407350705b39b87ab13dd1f1db0b1ae8eedc178debc057a1dd4d6ab4e2ac8b98144987f848504bbd0b00770c4906dfc121adb4fc0fad95621
|
data/bin/fylorg
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fylorg
|
4
|
+
require_relative "fylorg"
|
5
|
+
|
6
|
+
class Cli
|
7
|
+
def initialize(args)
|
8
|
+
@args = parse args
|
9
|
+
end
|
10
|
+
|
11
|
+
def run!
|
12
|
+
Fylorg::Base.new(@args).organize!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse(raw_args)
|
18
|
+
Hash[raw_args.map { |arg| arg.gsub('--', '').split('=') }]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "pry"
|
5
|
+
|
6
|
+
module Fylorg
|
7
|
+
class Fileman
|
8
|
+
def load_files_for_processing(opts)
|
9
|
+
files = String(opts[:types]).split(",").reduce([]) do |acc, filetype|
|
10
|
+
acc + Dir[File.join(root_dir(opts), "**", "*.#{filetype}")]
|
11
|
+
end
|
12
|
+
|
13
|
+
[files, opts]
|
14
|
+
end
|
15
|
+
|
16
|
+
def relocate!(categorized_files, opts)
|
17
|
+
categorized_files.map do |category, files|
|
18
|
+
category_path = File.join(opts[:out], category.to_s)
|
19
|
+
FileUtils.mkdir(category_path) unless File.exists?(category_path)
|
20
|
+
files.map do |categorized_file|
|
21
|
+
unless File.realdirpath(File.dirname(categorized_file)) == File.realdirpath(category_path)
|
22
|
+
FileUtils.mv(categorized_file, category_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def root_dir(opts)
|
31
|
+
opts[:root] || "**"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fylorg
|
4
|
+
require_relative "confparser"
|
5
|
+
require "levenshtein"
|
6
|
+
|
7
|
+
class Matcher
|
8
|
+
MATCH_THRESHOLD = 0.99
|
9
|
+
MATCH_FILT_LEVEL = 0.1
|
10
|
+
|
11
|
+
def categorize(files, opts)
|
12
|
+
[
|
13
|
+
generate_matches(files, opts).inject({}) { |mem, data| mem.merge(data) },
|
14
|
+
opts
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_matches(files, opts)
|
21
|
+
Fylorg::Confparser.new.parse(opts).map do |category, keywords|
|
22
|
+
match_for_category(files, category, keywords)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def match_for_category(files, category, keywords)
|
27
|
+
{
|
28
|
+
category => files.select do |file|
|
29
|
+
keywords_match?(
|
30
|
+
file.scan(/[a-zA-Z0-9]+/).select { |file_meta_word| file_meta_word.length >= 2 },
|
31
|
+
keywords
|
32
|
+
)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def keywords_match?(file_words, category_words)
|
38
|
+
(Levenshtein.normalized_distance(file_words, category_words, MATCH_THRESHOLD) || 0.0) >
|
39
|
+
MATCH_FILT_LEVEL
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/fylorg.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fylorg
|
4
|
+
require_relative "fylorg/confparser"
|
5
|
+
require_relative "fylorg/matcher"
|
6
|
+
require_relative "fylorg/fileman"
|
7
|
+
|
8
|
+
class Base
|
9
|
+
attr_accessor :opts
|
10
|
+
|
11
|
+
def initialize(raw_opts)
|
12
|
+
@opts = raw_opts.slice(*%w[dictionary out root types]).transform_keys(&:to_sym)
|
13
|
+
end
|
14
|
+
|
15
|
+
def organize!
|
16
|
+
Fylorg::Fileman.new.relocate!(
|
17
|
+
*Fylorg::Matcher.new.categorize(
|
18
|
+
*Fylorg::Fileman.new.load_files_for_processing(opts)
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fylorg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sreedev Kodichath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Organize files by name automatically
|
14
|
+
email: sreedevpadmakumar@gmail.com
|
15
|
+
executables:
|
16
|
+
- fylorg
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/fylorg
|
21
|
+
- lib/cli.rb
|
22
|
+
- lib/fylorg.rb
|
23
|
+
- lib/fylorg/confparser.rb
|
24
|
+
- lib/fylorg/fileman.rb
|
25
|
+
- lib/fylorg/matcher.rb
|
26
|
+
homepage: https://sree.dev/
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata:
|
30
|
+
source_code_uri: https://github.com/sreedevk/fylorg
|
31
|
+
post_install_message: |2
|
32
|
+
Thank you for installing fylorg
|
33
|
+
you may have to reshim if you use asdf/rbenv.
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.7.2
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.3.3
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: File Organizer
|
52
|
+
test_files: []
|