visionmedia-rext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +4 -0
- data/Manifest +19 -0
- data/README.rdoc +97 -0
- data/Rakefile +16 -0
- data/Todo.rdoc +14 -0
- data/lib/rext.rb +24 -0
- data/lib/rext/all.rb +13 -0
- data/lib/rext/integer.rb +7 -0
- data/lib/rext/integer/time.rb +57 -0
- data/lib/rext/string.rb +7 -0
- data/lib/rext/string/escape.rb +32 -0
- data/lib/rext/string/helpers.rb +151 -0
- data/lib/rext/version.rb +4 -0
- data/rext.gemspec +31 -0
- data/spec/integer_spec.rb +36 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/string_spec.rb +95 -0
- data/tasks/docs.rake +13 -0
- data/tasks/gemspec.rake +3 -0
- data/tasks/spec.rake +25 -0
- metadata +88 -0
data/History.rdoc
ADDED
data/Manifest
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
History.rdoc
|
2
|
+
lib/rext/all.rb
|
3
|
+
lib/rext/integer/time.rb
|
4
|
+
lib/rext/integer.rb
|
5
|
+
lib/rext/string/escape.rb
|
6
|
+
lib/rext/string/helpers.rb
|
7
|
+
lib/rext/string.rb
|
8
|
+
lib/rext/version.rb
|
9
|
+
lib/rext.rb
|
10
|
+
Manifest
|
11
|
+
Rakefile
|
12
|
+
README.rdoc
|
13
|
+
spec/integer_spec.rb
|
14
|
+
spec/spec_helper.rb
|
15
|
+
spec/string_spec.rb
|
16
|
+
tasks/docs.rake
|
17
|
+
tasks/gemspec.rake
|
18
|
+
tasks/spec.rake
|
19
|
+
Todo.rdoc
|
data/README.rdoc
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
= Rext
|
3
|
+
|
4
|
+
This gem is primarily used for the Evolution CMS project, and its dependencies,
|
5
|
+
however it is de-coupled and free to use within your own project. As to compliment
|
6
|
+
existing extension libraries such as extlib, this library does not provide
|
7
|
+
methods such as String#camelize etc.
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
require 'rext/all'
|
12
|
+
|
13
|
+
# or
|
14
|
+
|
15
|
+
require 'rext/string'
|
16
|
+
require 'rext/hash'
|
17
|
+
...
|
18
|
+
|
19
|
+
# or
|
20
|
+
|
21
|
+
require 'rext/string/escape'
|
22
|
+
require 'rext/enumerable/every'
|
23
|
+
...
|
24
|
+
|
25
|
+
== Extensions
|
26
|
+
|
27
|
+
Below are the methods currently provided by Rext.
|
28
|
+
|
29
|
+
* String
|
30
|
+
- url_encode
|
31
|
+
- url_decode
|
32
|
+
- html_escape
|
33
|
+
- merge_word / add_class
|
34
|
+
- digitize
|
35
|
+
- wrap
|
36
|
+
- start_with?
|
37
|
+
- end_with?
|
38
|
+
- plural?
|
39
|
+
- singular?
|
40
|
+
- first
|
41
|
+
- last
|
42
|
+
- file
|
43
|
+
- files
|
44
|
+
- path
|
45
|
+
|
46
|
+
* Integer
|
47
|
+
- ordanalize
|
48
|
+
- seconds, minutes, hours, days, ...
|
49
|
+
- to_seconds, to_minutes, to_hours, ...
|
50
|
+
- ago / before
|
51
|
+
- since / from_now
|
52
|
+
|
53
|
+
* Hash
|
54
|
+
- delete_at / extract!
|
55
|
+
|
56
|
+
* Time
|
57
|
+
- in_words_since / in_words_since_now
|
58
|
+
- to_time
|
59
|
+
|
60
|
+
* Date
|
61
|
+
- to_time
|
62
|
+
|
63
|
+
* Module
|
64
|
+
- chain
|
65
|
+
|
66
|
+
* Proc
|
67
|
+
- yield_or_eval
|
68
|
+
|
69
|
+
* Enumerable
|
70
|
+
- group_by
|
71
|
+
- every ( Copyright http://github.com/mynyml )
|
72
|
+
|
73
|
+
== License
|
74
|
+
|
75
|
+
(The MIT License)
|
76
|
+
|
77
|
+
Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
|
78
|
+
|
79
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
80
|
+
a copy of this software and associated documentation files (the
|
81
|
+
'Software'), to deal in the Software without restriction, including
|
82
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
83
|
+
distribute, sublicense, an d/or sell copies of the Software, and to
|
84
|
+
permit persons to whom the Software is furnished to do so, subject to
|
85
|
+
the following conditions:
|
86
|
+
|
87
|
+
The above copyright notice and this permission notice shall be
|
88
|
+
included in all copies or substantial portions of the Software.
|
89
|
+
|
90
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
91
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
92
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
93
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
94
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
95
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
96
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
97
|
+
ALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
$:.unshift 'lib'
|
3
|
+
require 'rext'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake'
|
6
|
+
require 'echoe'
|
7
|
+
|
8
|
+
Echoe.new "rext", Rext::VERSION do |p|
|
9
|
+
p.author = "TJ Holowaychuk"
|
10
|
+
p.email = "tj@vision-media.ca"
|
11
|
+
p.summary = "Ruby extensions"
|
12
|
+
p.url = "http://github.com/visionmedia/rext"
|
13
|
+
p.runtime_dependencies = []
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
|
data/Todo.rdoc
ADDED
data/lib/rext.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'rext/version'
|
data/lib/rext/all.rb
ADDED
data/lib/rext/integer.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
class Integer
|
3
|
+
|
4
|
+
def seconds; self end
|
5
|
+
def minutes; self * 60 end
|
6
|
+
def hours; self * 3600 end
|
7
|
+
def days; self * 86400 end
|
8
|
+
def weeks; self * 604800 end
|
9
|
+
def months; self * 2592000 end
|
10
|
+
def years; self * 31471200 end
|
11
|
+
|
12
|
+
alias :second :seconds
|
13
|
+
alias :minute :minutes
|
14
|
+
alias :hour :hours
|
15
|
+
alias :day :days
|
16
|
+
alias :week :weeks
|
17
|
+
alias :month :months
|
18
|
+
alias :year :years
|
19
|
+
|
20
|
+
def to_minutes; self / 1.minute end
|
21
|
+
def to_hours; self / 1.hour end
|
22
|
+
def to_days; self / 1.day end
|
23
|
+
def to_weeks; self / 1.week end
|
24
|
+
def to_months; self / 1.month end
|
25
|
+
def to_years; self / 1.year end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Time before specified +time+, which defaults to now.
|
29
|
+
#
|
30
|
+
# === Examples
|
31
|
+
#
|
32
|
+
# event = 10.days.ago
|
33
|
+
# 15.minutes.before event
|
34
|
+
#
|
35
|
+
|
36
|
+
def ago time = ::Time.now
|
37
|
+
time - self
|
38
|
+
end
|
39
|
+
alias :before :ago
|
40
|
+
|
41
|
+
##
|
42
|
+
# Time since specified +time+, which defaults to now.
|
43
|
+
#
|
44
|
+
# === Examples
|
45
|
+
#
|
46
|
+
# event = 1.year.ago
|
47
|
+
# 3.months.since event
|
48
|
+
#
|
49
|
+
# 4.days.from_now
|
50
|
+
#
|
51
|
+
|
52
|
+
def since time = ::Time.now
|
53
|
+
time + self
|
54
|
+
end
|
55
|
+
alias :from_now :since
|
56
|
+
|
57
|
+
end
|
data/lib/rext/string.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
class String
|
5
|
+
|
6
|
+
##
|
7
|
+
# URL encode. Shortcut for Rack::Utils.encode.
|
8
|
+
|
9
|
+
def url_encode
|
10
|
+
Rack::Utils.escape self
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# URL decode. Shortcut for Rack::Utils.unescape.
|
15
|
+
|
16
|
+
def url_decode
|
17
|
+
Rack::Utils.unescape self
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Escape html entities. Shortcut for Rack::Utils.escape_html.
|
22
|
+
#
|
23
|
+
# === Examples
|
24
|
+
#
|
25
|
+
# 'im <strong>strong</strong>.escape_html # => im <strong>strong</strong>
|
26
|
+
#
|
27
|
+
|
28
|
+
def escape_html
|
29
|
+
Rack::Utils.escape_html self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
|
2
|
+
require 'extlib'
|
3
|
+
|
4
|
+
class String
|
5
|
+
|
6
|
+
##
|
7
|
+
# Returns a File instance.
|
8
|
+
#
|
9
|
+
# === Examples
|
10
|
+
#
|
11
|
+
# 'History.rdoc'.file.mtime
|
12
|
+
#
|
13
|
+
|
14
|
+
def file
|
15
|
+
File.new self
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Returns a Pathname instance.
|
20
|
+
#
|
21
|
+
# === Examples
|
22
|
+
#
|
23
|
+
# 'lib'.path.join('foo').expand_path
|
24
|
+
#
|
25
|
+
|
26
|
+
def path
|
27
|
+
require 'pathname'
|
28
|
+
Pathname.new self
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Returns an array of files matching self.
|
33
|
+
#
|
34
|
+
# === Examples
|
35
|
+
#
|
36
|
+
# 'lib/**/*.rb'.files
|
37
|
+
#
|
38
|
+
|
39
|
+
def files
|
40
|
+
Dir[self]
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Merge the +word+ passed into the string. This
|
45
|
+
# is useful for adding classes which may already
|
46
|
+
# exist in a string.
|
47
|
+
#
|
48
|
+
# === Examples
|
49
|
+
#
|
50
|
+
# 'product'.merge_word('sold') # => "product sold"
|
51
|
+
# 'product sold'.merge_word('sold') # => "product sold"
|
52
|
+
#
|
53
|
+
|
54
|
+
def merge_word word
|
55
|
+
self << " #{word}" unless split.include? word
|
56
|
+
self
|
57
|
+
end
|
58
|
+
alias :add_class :merge_word
|
59
|
+
|
60
|
+
##
|
61
|
+
# Digitize a string.
|
62
|
+
#
|
63
|
+
# === Examples:
|
64
|
+
#
|
65
|
+
# '$100,000'.digitize # => 100000
|
66
|
+
#
|
67
|
+
|
68
|
+
def digitize
|
69
|
+
gsub /[^\d]/, ''
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Wrap a string with a +prefix+ and optional
|
74
|
+
# +suffix+. When the +suffix+ is not present
|
75
|
+
# the +prefix+ will be used.
|
76
|
+
#
|
77
|
+
# === Examples
|
78
|
+
#
|
79
|
+
# 'foo'.wrap('|') # => |foo|
|
80
|
+
# 'foo'.wrap('(', ')') # => (foo)
|
81
|
+
#
|
82
|
+
|
83
|
+
def wrap prefix, suffix = nil
|
84
|
+
prefix + self + (suffix || prefix)
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Check if a string starts with another +string+.
|
89
|
+
#
|
90
|
+
# === Examples
|
91
|
+
#
|
92
|
+
# 'foo bar'.start_with? 'foo' # => true
|
93
|
+
#
|
94
|
+
|
95
|
+
def start_with? string
|
96
|
+
index(string) == 0
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Check if a string ends with another +string+.
|
101
|
+
#
|
102
|
+
# === Examples
|
103
|
+
#
|
104
|
+
# 'foo bar'.end_with? 'bar' # => true
|
105
|
+
#
|
106
|
+
|
107
|
+
def end_with? string
|
108
|
+
rindex(string) == length - string.length
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Determines if a string is plural.
|
113
|
+
#
|
114
|
+
# === Examples
|
115
|
+
#
|
116
|
+
# 'cookies'.plural? # => true
|
117
|
+
# 'cookie'.plural? # => false
|
118
|
+
#
|
119
|
+
|
120
|
+
def plural?
|
121
|
+
singular != self
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Determines if a string is singular.
|
126
|
+
#
|
127
|
+
# === Examples
|
128
|
+
#
|
129
|
+
# 'cookies'.singular? # => false
|
130
|
+
# 'cookie'.singular? # => true
|
131
|
+
#
|
132
|
+
|
133
|
+
def singular?
|
134
|
+
!plural?
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# First character.
|
139
|
+
|
140
|
+
def first
|
141
|
+
self[0,1]
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Last character.
|
146
|
+
|
147
|
+
def last
|
148
|
+
self[-1, 1]
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
data/lib/rext/version.rb
ADDED
data/rext.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rext}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["TJ Holowaychuk"]
|
9
|
+
s.date = %q{2009-03-23}
|
10
|
+
s.description = %q{Ruby extensions}
|
11
|
+
s.email = %q{tj@vision-media.ca}
|
12
|
+
s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/integer/time.rb", "lib/rext/integer.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/version.rb", "lib/rext.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["History.rdoc", "lib/rext/all.rb", "lib/rext/integer/time.rb", "lib/rext/integer.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/version.rb", "lib/rext.rb", "Manifest", "Rakefile", "README.rdoc", "spec/integer_spec.rb", "spec/spec_helper.rb", "spec/string_spec.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "Todo.rdoc", "rext.gemspec"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/visionmedia/rext}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rext", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{rext}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Ruby extensions}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require 'rext/integer'
|
3
|
+
|
4
|
+
describe Integer do
|
5
|
+
describe "helpers" do
|
6
|
+
describe "#ordanalize" do
|
7
|
+
it "should convert integers to an ordanal string" do
|
8
|
+
1.ordinalize.should == '1st'
|
9
|
+
2.ordinalize.should == '2nd'
|
10
|
+
3.ordinalize.should == '3rd'
|
11
|
+
4.ordinalize.should == '4th'
|
12
|
+
11.ordinalize.should == '11th'
|
13
|
+
12.ordinalize.should == '12th'
|
14
|
+
13.ordinalize.should == '13th'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "time" do
|
20
|
+
|
21
|
+
describe "#ago / #before" do
|
22
|
+
it "should return the distance in time before now, or specified time" do
|
23
|
+
event = Time.mktime 1987, 5, 25
|
24
|
+
15.days.before(event).should == Time.mktime(1987, 5, 10)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#since / #from_now" do
|
29
|
+
it "should return the distance in time from now, or specified time" do
|
30
|
+
event = Time.mktime 1987, 5, 25
|
31
|
+
5.days.since(event).should == Time.mktime(1987, 5, 30)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
require 'rext/string'
|
3
|
+
|
4
|
+
describe String do
|
5
|
+
describe "helpers" do
|
6
|
+
|
7
|
+
describe "#path" do
|
8
|
+
it "should return an instance of a pathname" do
|
9
|
+
'History.rdoc'.path.should be_an_instance_of(Pathname)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#files" do
|
14
|
+
it "should return result of Dir glob" do
|
15
|
+
'lib/*.*'.files.should be_an_instance_of(Array)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#file" do
|
20
|
+
it "should return an instance of a file" do
|
21
|
+
'History.rdoc'.file.should be_an_instance_of(File)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#add_class" do
|
26
|
+
it "should add a word that does not exist" do
|
27
|
+
'foo'.add_class('bar').should == 'foo bar'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not add the same word twice" do
|
31
|
+
'foo-bar bar'.add_class('bar').should == 'foo-bar bar'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#wrap" do
|
36
|
+
it "should wrap a string" do
|
37
|
+
'foo'.wrap('|').should == '|foo|'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should wrap with optional suffix" do
|
41
|
+
'foo'.wrap('(', ')').should == '(foo)'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#start_with?" do
|
46
|
+
it "should check if a string starts with another" do
|
47
|
+
'foo bar'.start_with?('foo').should be_true
|
48
|
+
' foo bar'.start_with?('foo').should_not be_true
|
49
|
+
'bar foo'.start_with?('foo').should_not be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#end_with?" do
|
54
|
+
it "should check if a string ends with another" do
|
55
|
+
'foo bar'.end_with?('bar').should be_true
|
56
|
+
'foo bar '.end_with?('bar').should_not be_true
|
57
|
+
'bar foo foo'.end_with?('foo').should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#plural?" do
|
62
|
+
it "should check if a string is plural" do
|
63
|
+
'cookies'.should be_plural
|
64
|
+
'cookie'.should_not be_plural
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#singular?" do
|
69
|
+
it "should check if a string is singular" do
|
70
|
+
'cookie'.should be_singular
|
71
|
+
'cookies'.should_not be_singular
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#first" do
|
76
|
+
it "should return the first character" do
|
77
|
+
'foo'.first.should == 'f'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#last" do
|
82
|
+
it "should return the last character" do
|
83
|
+
'bar'.last.should == 'r'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#digitize" do
|
88
|
+
it "should leave only numeric characters" do
|
89
|
+
'$100,000'.digitize.should == '100000'
|
90
|
+
'$100,000'.digitize.to_i.should == 100_000
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
data/tasks/docs.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
namespace :docs do
|
3
|
+
|
4
|
+
desc 'Remove rdoc products'
|
5
|
+
task :remove => [:clobber_docs]
|
6
|
+
|
7
|
+
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
8
|
+
task :open => [:docs] do
|
9
|
+
browser = ENV["BROWSER"] || "safari"
|
10
|
+
sh "open -a #{browser} doc/index.html"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/tasks/gemspec.rake
ADDED
data/tasks/spec.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run all specifications"
|
5
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
6
|
+
t.libs << "lib"
|
7
|
+
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :spec do
|
11
|
+
|
12
|
+
desc "Run all specifications verbosely"
|
13
|
+
Spec::Rake::SpecTask.new(:verbose) do |t|
|
14
|
+
t.libs << "lib"
|
15
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run specific specification verbosely (specify SPEC)"
|
19
|
+
Spec::Rake::SpecTask.new(:select) do |t|
|
20
|
+
t.libs << "lib"
|
21
|
+
t.spec_files = [ENV["SPEC"]]
|
22
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visionmedia-rext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TJ Holowaychuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby extensions
|
17
|
+
email: tj@vision-media.ca
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/rext/all.rb
|
24
|
+
- lib/rext/integer/time.rb
|
25
|
+
- lib/rext/integer.rb
|
26
|
+
- lib/rext/string/escape.rb
|
27
|
+
- lib/rext/string/helpers.rb
|
28
|
+
- lib/rext/string.rb
|
29
|
+
- lib/rext/version.rb
|
30
|
+
- lib/rext.rb
|
31
|
+
- README.rdoc
|
32
|
+
- tasks/docs.rake
|
33
|
+
- tasks/gemspec.rake
|
34
|
+
- tasks/spec.rake
|
35
|
+
files:
|
36
|
+
- History.rdoc
|
37
|
+
- lib/rext/all.rb
|
38
|
+
- lib/rext/integer/time.rb
|
39
|
+
- lib/rext/integer.rb
|
40
|
+
- lib/rext/string/escape.rb
|
41
|
+
- lib/rext/string/helpers.rb
|
42
|
+
- lib/rext/string.rb
|
43
|
+
- lib/rext/version.rb
|
44
|
+
- lib/rext.rb
|
45
|
+
- Manifest
|
46
|
+
- Rakefile
|
47
|
+
- README.rdoc
|
48
|
+
- spec/integer_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
- spec/string_spec.rb
|
51
|
+
- tasks/docs.rake
|
52
|
+
- tasks/gemspec.rake
|
53
|
+
- tasks/spec.rake
|
54
|
+
- Todo.rdoc
|
55
|
+
- rext.gemspec
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/visionmedia/rext
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --line-numbers
|
61
|
+
- --inline-source
|
62
|
+
- --title
|
63
|
+
- Rext
|
64
|
+
- --main
|
65
|
+
- README.rdoc
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "1.2"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: rext
|
83
|
+
rubygems_version: 1.2.0
|
84
|
+
signing_key:
|
85
|
+
specification_version: 2
|
86
|
+
summary: Ruby extensions
|
87
|
+
test_files: []
|
88
|
+
|