fun_with_files 0.0.1 → 0.0.2
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.
- data/VERSION +1 -1
- data/lib/files/file_path.rb +42 -8
- data/lib/files/pathname_extensions.rb +5 -0
- data/lib/fun_with_files.rb +1 -0
- data/test/test_file_path.rb +21 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/files/file_path.rb
CHANGED
@@ -204,14 +204,15 @@ module FunWith
|
|
204
204
|
split_basename.length > 1 ? split_basename.last : ""
|
205
205
|
end
|
206
206
|
|
207
|
-
#
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
207
|
+
# base, ext = @path.basename_and_ext
|
208
|
+
def basename_and_ext
|
209
|
+
[basename_no_ext, ext]
|
210
|
+
end
|
211
|
+
|
212
|
+
# Basically Pathname.relative_path_from, but you can pass in strings
|
213
|
+
def relative_path_from( dir )
|
214
|
+
dir = super( Pathname.new( dir ) )
|
215
|
+
self.class.new( dir )
|
215
216
|
end
|
216
217
|
|
217
218
|
# gsub acts on the filepath, not the file contents
|
@@ -227,6 +228,39 @@ module FunWith
|
|
227
228
|
def fwf_filepath
|
228
229
|
self
|
229
230
|
end
|
231
|
+
|
232
|
+
# Gives a sequence of files. Examples:
|
233
|
+
# file.dat --> file.000000.dat
|
234
|
+
# file_without_ext --> file_without_ext.000000
|
235
|
+
# If it sees a six-digit number at or near the end of the
|
236
|
+
# filename, it increments it.
|
237
|
+
#
|
238
|
+
# You can change the length of the sequence string by passing
|
239
|
+
# in an argument, but it should always be the same value for
|
240
|
+
# a given set of files.
|
241
|
+
SUCC_DIGIT_COUNT = 6
|
242
|
+
def succ( digit_count = SUCC_DIGIT_COUNT )
|
243
|
+
chunks = basename.to_s.split(".")
|
244
|
+
if chunks.length == 1 # not being counted, no file extension.
|
245
|
+
chunks.push( "0" * digit_count )
|
246
|
+
elsif match_data = chunks[-2].match( /^(\d{#{digit_count}})$/ )
|
247
|
+
i = match_data[1].to_i + 1
|
248
|
+
chunks[-2] = sprintf("%0#{digit_count}i", i)
|
249
|
+
elsif match_data = chunks[-1].match( /^(\d{#{digit_count}})$/ )
|
250
|
+
i = match_data[1].to_i + 1
|
251
|
+
chunks[-1] = sprintf("%0#{digit_count}i", i)
|
252
|
+
else # not being counted, has file extension
|
253
|
+
chunks = [chunks[0..-2], ("0" * digit_count), chunks[-1]].flatten
|
254
|
+
end
|
255
|
+
|
256
|
+
self.up.join( chunks.join(".") )
|
257
|
+
end
|
230
258
|
end
|
259
|
+
|
260
|
+
# TODO: succession : enumerates a sequence of files that get passed
|
261
|
+
# to a block in order.
|
262
|
+
|
263
|
+
# TODO: succ_last : find the last existing file of the given sequence.
|
264
|
+
# TODO: succ_next : find the first free file of the given sequence
|
231
265
|
end
|
232
266
|
end
|
data/lib/fun_with_files.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative File.join("files", "file_path")
|
|
7
7
|
require_relative File.join("files", "root_path")
|
8
8
|
require_relative File.join("files", "remote_path")
|
9
9
|
require_relative File.join("files", "string_extensions")
|
10
|
+
require_relative File.join("files", "pathname_extensions")
|
10
11
|
|
11
12
|
FunWith::Files::RootPath.rootify( FunWith::Files, FunWith::Files::FilePath.new(__FILE__).dirname.up )
|
12
13
|
|
data/test/test_file_path.rb
CHANGED
@@ -32,6 +32,27 @@ class TestFilePath < Test::Unit::TestCase
|
|
32
32
|
#invoking down didn't change original
|
33
33
|
assert_no_match /ask_for_floyd/, f2.to_s
|
34
34
|
end
|
35
|
+
|
36
|
+
should "convert from string" do
|
37
|
+
str = "/"
|
38
|
+
f1 = FilePath.new(str)
|
39
|
+
f2 = str.fwf_filepath
|
40
|
+
|
41
|
+
assert_equal f1, f2
|
42
|
+
end
|
43
|
+
|
44
|
+
should "convert from pathname" do
|
45
|
+
str = "/"
|
46
|
+
f1 = FilePath.new(str)
|
47
|
+
f2 = Pathname.new(str).fwf_filepath
|
48
|
+
|
49
|
+
assert_equal f1, f2
|
50
|
+
|
51
|
+
f3 = f1.join( "bin", "bash" )
|
52
|
+
f4 = Pathname.new( str ).fwf_filepath( "bin", "bash" )
|
53
|
+
|
54
|
+
assert_equal f3, f4
|
55
|
+
end
|
35
56
|
end
|
36
57
|
|
37
58
|
context "test glob" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -106,6 +106,7 @@ extra_rdoc_files:
|
|
106
106
|
- README.rdoc
|
107
107
|
files:
|
108
108
|
- ./lib/files/file_path.rb
|
109
|
+
- ./lib/files/pathname_extensions.rb
|
109
110
|
- ./lib/files/remote_path.rb
|
110
111
|
- ./lib/files/root_path.rb
|
111
112
|
- ./lib/files/string_extensions.rb
|
@@ -137,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
segments:
|
139
140
|
- 0
|
140
|
-
hash: -
|
141
|
+
hash: -2333632354630146614
|
141
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
143
|
none: false
|
143
144
|
requirements:
|