crowd_support 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/crowd_support/core_ext/string.rb +33 -33
- data/lib/crowd_support.rb +3 -3
- metadata +7 -7
@@ -1,33 +1,33 @@
|
|
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
|
-
#
|
17
|
-
# source: http://stackoverflow.com/a/10823131
|
18
|
-
def sanitize_filename
|
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
|
24
|
-
|
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, '_' }
|
29
|
-
|
30
|
-
# Finally, join the parts with a period and return the result
|
31
|
-
return fn.join '.'
|
32
|
-
end
|
33
|
-
end
|
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
|
+
#
|
17
|
+
# source: http://stackoverflow.com/a/10823131
|
18
|
+
def sanitize_filename
|
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
|
24
|
+
|
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, '_' }
|
29
|
+
|
30
|
+
# Finally, join the parts with a period and return the result
|
31
|
+
return fn.join '.'
|
32
|
+
end
|
33
|
+
end
|
data/lib/crowd_support.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module CrowdSupport
|
2
|
-
require 'crowd_support/core_ext/string'
|
3
|
-
end
|
1
|
+
module CrowdSupport
|
2
|
+
require 'crowd_support/core_ext/string'
|
3
|
+
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70327640510040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70327640510040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70327640508440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70327640508440
|
36
36
|
description: Incorporating solutions found on Google, StackExchange, etc. that I've
|
37
37
|
needed to use more than once
|
38
38
|
email: aaronbreckenridge@gmail.com
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
version: 1.3.6
|
64
64
|
requirements: []
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.8.10
|
67
67
|
signing_key:
|
68
68
|
specification_version: 3
|
69
69
|
summary: solutions to common problems sourced from the internet
|