roopap 0.0.5 → 0.0.6
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 +4 -4
- data/lib/roopap/organizer.rb +11 -4
- data/lib/roopap/version.rb +1 -1
- data/spec/integration_spec.rb +2 -2
- data/spec/lib/organizer_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f500a3565a08cf7ab821172f49331c39b4f7b5ee
|
4
|
+
data.tar.gz: bdd59573c7f1153bfc0482ae14fa9684dc636db3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4701be3a6cc3cc581c582c79c41cf11b7c14f7a0966ab07a6b61ca862bf81884a491fcf81dc6256615e082ddfb93dcf006ef25bd2322692a9d524e7f1131231a
|
7
|
+
data.tar.gz: 2f9ab9bd7b3c6078ee1e944ed66689073226c6efa52b9147a25e3aec8a9cacfc2b3f3b5f04a524930f98b0de0251524a25944d9ee0b3705d808c4dbc8eb9b23a
|
data/lib/roopap/organizer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'exifr'
|
2
2
|
require 'pathname'
|
3
3
|
require 'time'
|
4
|
+
require 'digest'
|
4
5
|
|
5
6
|
module Roopap
|
6
7
|
class Organizer
|
@@ -13,7 +14,6 @@ module Roopap
|
|
13
14
|
src_file_path = c.to_s
|
14
15
|
next unless jpg_file?(src_file_path)
|
15
16
|
target_path = dest_for(src_file_path, dest)
|
16
|
-
prepare_dir(target_path)
|
17
17
|
copy(src_file_path, target_path)
|
18
18
|
inc_success_number
|
19
19
|
end
|
@@ -37,7 +37,10 @@ module Roopap
|
|
37
37
|
photo = EXIFR::JPEG.new(filepath)
|
38
38
|
time = get_time(photo)
|
39
39
|
dir_name = time.utc.strftime('%Y-%m')
|
40
|
-
File.join(root, dir_name)
|
40
|
+
dir_path = File.join(root, dir_name)
|
41
|
+
prepare_dir(dir_path)
|
42
|
+
filename = gen_filename(time, filepath)
|
43
|
+
File.join(dir_path, filename)
|
41
44
|
end
|
42
45
|
|
43
46
|
def get_time(photo)
|
@@ -47,12 +50,16 @@ module Roopap
|
|
47
50
|
time
|
48
51
|
end
|
49
52
|
|
53
|
+
def gen_filename(time, filepath)
|
54
|
+
"#{time.to_i}-#{Digest::MD5.hexdigest(File.read(filepath))[0..9]}.jpg"
|
55
|
+
end
|
56
|
+
|
50
57
|
def prepare_dir(path)
|
51
58
|
FileUtils.mkdir_p(path)
|
52
59
|
end
|
53
60
|
|
54
|
-
def copy(filepath,
|
55
|
-
FileUtils.cp(filepath,
|
61
|
+
def copy(filepath, dest_path)
|
62
|
+
FileUtils.cp(filepath, dest_path)
|
56
63
|
end
|
57
64
|
|
58
65
|
def inc_success_number
|
data/lib/roopap/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -19,8 +19,8 @@ describe "Calling Roopap via shell command" do
|
|
19
19
|
|
20
20
|
`bin/roopap #{from} #{target}`
|
21
21
|
|
22
|
-
assert FileTest.exists?("#{target}/2006-01/
|
23
|
-
assert FileTest.exists?("#{target}/2011-04/
|
22
|
+
assert FileTest.exists?("#{target}/2006-01/1137496843-e489272393.jpg"), "No file in the target directory"
|
23
|
+
assert FileTest.exists?("#{target}/2011-04/1301726919-bb455c47e4.jpg"), "No file in the target directory"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "displays number of copied files" do
|
data/spec/lib/organizer_spec.rb
CHANGED
@@ -22,8 +22,8 @@ module Roopap
|
|
22
22
|
|
23
23
|
Organizer.new.perform(source, target)
|
24
24
|
|
25
|
-
assert FileTest.exists?("#{target}/2006-01/
|
26
|
-
assert FileTest.exists?("#{target}/2011-04/
|
25
|
+
assert FileTest.exists?("#{target}/2006-01/1137496843-e489272393.jpg"), "No file in the target directory"
|
26
|
+
assert FileTest.exists?("#{target}/2011-04/1301726919-bb455c47e4.jpg"), "No file in the target directory"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "ignores non jpg file" do
|
@@ -32,7 +32,7 @@ module Roopap
|
|
32
32
|
|
33
33
|
Organizer.new.perform(source, target)
|
34
34
|
|
35
|
-
assert FileTest.exists?("#{target}/2006-01/
|
35
|
+
assert FileTest.exists?("#{target}/2006-01/1137496843-e489272393.jpg"), "No file in the target directory"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "returns number of organized files" do
|
@@ -55,7 +55,7 @@ module Roopap
|
|
55
55
|
o.perform(source, target)
|
56
56
|
end
|
57
57
|
|
58
|
-
assert FileTest.exists?("#{target}/2011-02/
|
58
|
+
assert FileTest.exists?("#{target}/2011-02/1297863330-e489272393.jpg"), "No file in the target directory"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roopap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nuttanart Pornprasitsakul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|