crowd_support 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/crowd_support/core_ext/string.rb +26 -11
- metadata +3 -3
data/README.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Solutions to
|
1
|
+
Solutions found on Google, StackExchange, etc. that I've needed to use more than once.
|
@@ -1,18 +1,33 @@
|
|
1
1
|
class String
|
2
|
+
# Returns a filename that doesn't already exist.
|
3
|
+
#
|
4
|
+
# source: http://www.ruby-forum.com/topic/191831
|
5
|
+
def next_filename
|
6
|
+
count = 0
|
7
|
+
unique_name = dup
|
8
|
+
while File.exists?(unique_name)
|
9
|
+
count += 1
|
10
|
+
unique_name = "#{File.join(File.dirname(dup), File.basename(dup, ".*"))}_#{count}#{File.extname(dup)}"
|
11
|
+
end
|
12
|
+
unique_name
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a filename with all non-alphanumeric characters removed.
|
16
|
+
#
|
2
17
|
# source: http://stackoverflow.com/a/10823131
|
3
18
|
def sanitize_filename
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
19
|
+
# Split the name when finding a period which is preceded by some
|
20
|
+
# character, and is followed by some character other than a period,
|
21
|
+
# if there is no following period that is followed by something
|
22
|
+
# other than a period (yeah, confusing, I know)
|
23
|
+
fn = dup.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m
|
9
24
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
25
|
+
# We now have one or two parts (depending on whether we could find
|
26
|
+
# a suitable period). For each of these parts, replace any unwanted
|
27
|
+
# sequence of characters with an underscore
|
28
|
+
fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '_' }
|
14
29
|
|
15
|
-
|
16
|
-
|
30
|
+
# Finally, join the parts with a period and return the result
|
31
|
+
return fn.join '.'
|
17
32
|
end
|
18
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowd_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-08-22 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Incorporating solutions found on Google, StackExchange, etc. that I've
|
15
15
|
needed to use more than once
|
16
16
|
email: aaronbreckenridge@gmail.com
|
17
17
|
executables: []
|
@@ -21,7 +21,7 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- lib/crowd_support/core_ext/string.rb
|
23
23
|
- lib/crowd_support.rb
|
24
|
-
homepage:
|
24
|
+
homepage: https://github.com/breckenedge/crowd_support
|
25
25
|
licenses: []
|
26
26
|
post_install_message:
|
27
27
|
rdoc_options: []
|