findler 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -104,9 +104,9 @@ class Findler::Filters
104
104
  end
105
105
 
106
106
  f = Findler.new "/Users/mrm"
107
- f.add_extensions ".jpg", ".jpeg", ".cr2", ".nef"
107
+ f.add_extensions %w(.jpg .jpeg .cr2 .nef)
108
108
  f.case_insensitive!
109
- f.add_filter(:exif_only)
109
+ f.add_filter :exif_only
110
110
  ```
111
111
 
112
112
  ### Filter implementation notes
@@ -123,6 +123,10 @@ Because procs and lambdas aren't ```Marshal```able, and I didn't want to use som
123
123
 
124
124
  ## Changelog
125
125
 
126
+ ### 0.0.6
127
+ * ```add_filters``` takes an array, not a glob
128
+ * added tests for order_by_mtime filters
129
+
126
130
  ### 0.0.5
127
131
  * ```add_patterns``` and ```add_extensions``` take an array, not a glob
128
132
 
data/lib/findler.rb CHANGED
@@ -86,7 +86,7 @@ class Findler
86
86
  (@filters ||= [])
87
87
  end
88
88
 
89
- def add_filters(*filter_symbols)
89
+ def add_filters(filter_symbols)
90
90
  filter_symbols.each { |ea| add_filter(ea) }
91
91
  end
92
92
 
@@ -11,12 +11,12 @@ class Findler::Filters
11
11
 
12
12
  # order by the mtime of each file. Oldest files first.
13
13
  def self.order_by_mtime_asc(paths)
14
- preserve_sort_by(paths) { |ea| ea.mtime }
14
+ preserve_sort_by(paths) { |ea| ea.mtime.to_i }
15
15
  end
16
16
 
17
17
  # reverse order by the mtime of each file. Newest files first.
18
18
  def self.order_by_mtime_desc(paths)
19
- preserve_sort_by(paths) { |ea| -ea.mtime }
19
+ preserve_sort_by(paths) { |ea| -1 * ea.mtime.to_i }
20
20
  end
21
21
 
22
22
  # order by the name of each file.
@@ -1,3 +1,3 @@
1
1
  class Findler
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/test/filters_test.rb CHANGED
@@ -1,15 +1,30 @@
1
1
  require 'minitest_helper'
2
2
 
3
3
  describe Findler::Filters do
4
- it "should preserve sort order with no result" do
4
+ it "preserves sort order with no result" do
5
5
  a = %w(h a p p y)
6
6
  b = Findler::Filters.preserve_sort_by(a) { 0 }
7
7
  b.must_equal a
8
8
  end
9
9
 
10
- it "should preserve sort order" do
10
+ it "preserves sort order" do
11
11
  a = [3.5, 3.1, 1.1, 2.0, 1.5, 1.3]
12
12
  b = Findler::Filters.preserve_sort_by(a) { |ea| ea.to_i }
13
13
  b.must_equal [1.1, 1.5, 1.3, 2.0, 3.5, 3.1]
14
14
  end
15
+
16
+ it "sorts by mtime" do
17
+ with_tmp_dir do
18
+ srand(8675309) # <- stable rand()
19
+ names = 10.times.collect { rand_alphanumeric + ".txt" }
20
+ names.each_with_index do |ea, index|
21
+ FileUtils.touch ea, :mtime => (Time.now.to_i + index)
22
+ end
23
+ paths = names.collect { |ea| Pathname.new(ea) }
24
+ glob = Pathname.glob("*.txt")
25
+ glob.wont_equal(paths) # because the order was random.
26
+ Findler::Filters.order_by_mtime_asc(glob).must_equal(paths)
27
+ Findler::Filters.order_by_mtime_desc(glob).must_equal(paths.reverse)
28
+ end
29
+ end
15
30
  end
data/test/findler_test.rb CHANGED
@@ -199,7 +199,7 @@ describe Findler do
199
199
  :subdirs_per_dir => 1,
200
200
  }) do |dir|
201
201
  f = Findler.new(dir)
202
- f.add_filters :order_by_name, :files_first
202
+ f.add_filters([:order_by_name, :files_first])
203
203
  expected = %W(tmp-0.a tmp-1.a dir-0/tmp-0.a dir-0/tmp-1.a)
204
204
  collect_files(f.iterator).must_equal expected
205
205
  f.add_filter :reverse
@@ -214,7 +214,7 @@ describe Findler do
214
214
  :subdirs_per_dir => 1,
215
215
  }) do |dir|
216
216
  f = Findler.new(dir)
217
- f.add_filters :order_by_name, :directories_first
217
+ f.add_filters([:order_by_name, :directories_first])
218
218
  expected = %W(dir-0/tmp-0.a dir-0/tmp-1.a tmp-0.a tmp-1.a)
219
219
  collect_files(f.iterator).must_equal expected
220
220
  f.add_filter :reverse
@@ -74,3 +74,10 @@ def fs_case_sensitive?
74
74
  `rm CASETEST`
75
75
  end
76
76
  end
77
+
78
+ ALPHANUMERIC = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a).freeze
79
+ def rand_alphanumeric(length = 10)
80
+ (0..length).collect do
81
+ ALPHANUMERIC[rand(ALPHANUMERIC.length)]
82
+ end.join
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: -249993079478696622
133
+ hash: 1051954001939010091
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: -249993079478696622
142
+ hash: 1051954001939010091
143
143
  requirements: []
144
144
  rubyforge_project:
145
145
  rubygems_version: 1.8.23