roopap 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89351518736a65641e7e7183848e0627c5658d5f
4
- data.tar.gz: 96f1c05f4f3636e17297c13437264c2035690a04
3
+ metadata.gz: f500a3565a08cf7ab821172f49331c39b4f7b5ee
4
+ data.tar.gz: bdd59573c7f1153bfc0482ae14fa9684dc636db3
5
5
  SHA512:
6
- metadata.gz: 7a1fdfbb244964b1b9c72d7bc87701daa1c22eef9005ed8c144fb1d2352864e022e97ee52c029f5d1aac2d4e1746a5af4ec7ee8aa50c97d68fee25c3e7af377f
7
- data.tar.gz: bb2b5da421a751c12355c21bb383eb45e768e3b32a447bec29e36067f46c0ac1b21c608f6f3f04638a249a1c836dbdb1319ec511e6f82257e11d513050917b83
6
+ metadata.gz: 4701be3a6cc3cc581c582c79c41cf11b7c14f7a0966ab07a6b61ca862bf81884a491fcf81dc6256615e082ddfb93dcf006ef25bd2322692a9d524e7f1131231a
7
+ data.tar.gz: 2f9ab9bd7b3c6078ee1e944ed66689073226c6efa52b9147a25e3aec8a9cacfc2b3f3b5f04a524930f98b0de0251524a25944d9ee0b3705d808c4dbc8eb9b23a
@@ -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, dest)
55
- FileUtils.cp(filepath, dest)
61
+ def copy(filepath, dest_path)
62
+ FileUtils.cp(filepath, dest_path)
56
63
  end
57
64
 
58
65
  def inc_success_number
@@ -1,3 +1,3 @@
1
1
  module Roopap
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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/a.jpg"), "No file in the target directory"
23
- assert FileTest.exists?("#{target}/2011-04/b.jpg"), "No file in the target directory"
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
@@ -22,8 +22,8 @@ module Roopap
22
22
 
23
23
  Organizer.new.perform(source, target)
24
24
 
25
- assert FileTest.exists?("#{target}/2006-01/a.jpg"), "No file in the target directory"
26
- assert FileTest.exists?("#{target}/2011-04/b.jpg"), "No file in the target directory"
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/a.jpg"), "No file in the target directory"
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/a.jpg"), "No file in the target directory"
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.5
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-13 00:00:00.000000000 Z
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler