visionmedia-rext 0.0.2 → 0.0.3
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/History.rdoc +7 -0
- data/README.rdoc +2 -0
- data/Todo.rdoc +1 -0
- data/lib/rext/all.rb +1 -0
- data/lib/rext/string/helpers.rb +41 -0
- data/lib/rext/version.rb +1 -1
- data/rext.gemspec +2 -2
- data/spec/string_spec.rb +33 -0
- metadata +2 -2
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
data/Todo.rdoc
CHANGED
data/lib/rext/all.rb
CHANGED
data/lib/rext/string/helpers.rb
CHANGED
@@ -3,6 +3,30 @@ require 'extlib'
|
|
3
3
|
|
4
4
|
class String
|
5
5
|
|
6
|
+
##
|
7
|
+
# Return Base 64 decoded string.
|
8
|
+
#
|
9
|
+
# === Examples
|
10
|
+
#
|
11
|
+
# 'Y29va2llcw=='.base64_decode # => cookies
|
12
|
+
#
|
13
|
+
|
14
|
+
def base64_decode
|
15
|
+
unpack('m').first
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Return Base 64 encoded string.
|
20
|
+
#
|
21
|
+
# === Examples
|
22
|
+
#
|
23
|
+
# 'cookies'.base64_encode # => Y29va2llcw==
|
24
|
+
#
|
25
|
+
|
26
|
+
def base64_encode
|
27
|
+
[self].pack('m').chop
|
28
|
+
end
|
29
|
+
|
6
30
|
##
|
7
31
|
# Returns a File instance.
|
8
32
|
#
|
@@ -69,6 +93,23 @@ class String
|
|
69
93
|
gsub /[^\d]/, ''
|
70
94
|
end
|
71
95
|
|
96
|
+
##
|
97
|
+
# Returns a constant when the string is a valid constant name.
|
98
|
+
|
99
|
+
def constantize
|
100
|
+
Extlib::Inflection.constantize self
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Convert a string to camel-case, and optionally +capitalize_first_letter+.
|
105
|
+
|
106
|
+
def camelize capitalize_first_letter = false
|
107
|
+
string = Extlib::Inflection.camelize(self)
|
108
|
+
return string if capitalize_first_letter
|
109
|
+
string[0,1] = string.first.downcase
|
110
|
+
string
|
111
|
+
end
|
112
|
+
|
72
113
|
##
|
73
114
|
# Wrap a string with a +prefix+ and optional
|
74
115
|
# +suffix+. When the +suffix+ is not present
|
data/lib/rext/version.rb
CHANGED
data/rext.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rext}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
|
-
s.date = %q{2009-03-
|
9
|
+
s.date = %q{2009-03-25}
|
10
10
|
s.description = %q{Ruby extensions}
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
12
12
|
s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer/time.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "README.rdoc", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
data/spec/string_spec.rb
CHANGED
@@ -4,6 +4,19 @@ require 'rext/string'
|
|
4
4
|
describe String do
|
5
5
|
describe "helpers" do
|
6
6
|
|
7
|
+
describe "#base64_encode" do
|
8
|
+
it "should base64 encode a string" do
|
9
|
+
'tj'.base64_encode.should == 'dGo='
|
10
|
+
"foo \n bar\n\n".base64_encode.base64_decode.should == "foo \n bar\n\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#base64_decode" do
|
15
|
+
it "should decode a base64 string" do
|
16
|
+
'dGo='.base64_decode.should == 'tj'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
describe "#path" do
|
8
21
|
it "should return an instance of a pathname" do
|
9
22
|
'History.rdoc'.path.should be_an_instance_of(Pathname)
|
@@ -83,6 +96,26 @@ describe String do
|
|
83
96
|
'bar'.last.should == 'r'
|
84
97
|
end
|
85
98
|
end
|
99
|
+
|
100
|
+
describe "#camelize" do
|
101
|
+
it "should camel-case a string, leaving the first character lower by default" do
|
102
|
+
'some_foo_bar'.camelize.should == 'someFooBar'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should camel-case a string, with first character capitalized" do
|
106
|
+
'some_foo_bar'.camelize(true).should == 'SomeFooBar'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#constantize" do
|
111
|
+
it "should convert a string to a constant" do
|
112
|
+
'Rext::VERSION'.constantize.should == Rext::VERSION
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should raise an error when an invalid constant name is passed" do
|
116
|
+
lambda { 'foo bar'.constantize }.should raise_error(NameError)
|
117
|
+
end
|
118
|
+
end
|
86
119
|
|
87
120
|
describe "#digitize" do
|
88
121
|
it "should leave only numeric characters" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-rext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|