kelredd-useful 0.2.3 → 0.2.4
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/lib/useful/ruby_extensions/string.rb +20 -2
- data/lib/useful/version.rb +1 -1
- metadata +2 -2
@@ -108,6 +108,20 @@ module Useful::RubyExtensions::String
|
|
108
108
|
end
|
109
109
|
end unless ::String.respond_to?('camelize')
|
110
110
|
|
111
|
+
# Create a class name from a string like Rails does for table names to models.
|
112
|
+
# => Note: unlike Rails, this one does not use inflectors to singularize
|
113
|
+
# => Note: this returns a string and not a Class. (To convert to an actual class
|
114
|
+
# follow +classify+ with +constantize+.)
|
115
|
+
#
|
116
|
+
# Examples:
|
117
|
+
# "egg_and_hams".classify # => "EggAndHams"
|
118
|
+
# "active_record/errors".classify # => "ActiveRecord::Errors"
|
119
|
+
# "active_record.error".classify # => "Error"
|
120
|
+
def classify(class_str)
|
121
|
+
# strip out any leading schema name
|
122
|
+
camelize(class_str.to_s.sub(/.*\./, ''))
|
123
|
+
end unless ::String.respond_to?('classify')
|
124
|
+
|
111
125
|
# Capitalizes the first word and turns underscores into spaces and strips a
|
112
126
|
# trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
|
113
127
|
#
|
@@ -117,7 +131,7 @@ module Useful::RubyExtensions::String
|
|
117
131
|
def humanize(lower_case_and_underscored_word)
|
118
132
|
result = lower_case_and_underscored_word.to_s.dup
|
119
133
|
result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
120
|
-
end
|
134
|
+
end unless ::String.respond_to?('humanize')
|
121
135
|
|
122
136
|
# Capitalizes all the words and replaces some characters in the string to create
|
123
137
|
# a nicer looking title. +titleize+ is meant for creating pretty output. It is not
|
@@ -128,7 +142,7 @@ module Useful::RubyExtensions::String
|
|
128
142
|
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
|
129
143
|
def titleize(word)
|
130
144
|
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
|
131
|
-
end
|
145
|
+
end unless ::String.respond_to?('titleize')
|
132
146
|
|
133
147
|
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
134
148
|
#
|
@@ -217,6 +231,10 @@ module Useful::RubyExtensions::String
|
|
217
231
|
end unless "".respond_to?('camelize')
|
218
232
|
alias_method :camelcase, :camelize unless "".respond_to?('camelcase')
|
219
233
|
|
234
|
+
def classify
|
235
|
+
self.class.classify(self)
|
236
|
+
end unless "".respond_to?('classify')
|
237
|
+
|
220
238
|
def humanize
|
221
239
|
self.class.humanize(self)
|
222
240
|
end unless "".respond_to?('humanize')
|
data/lib/useful/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelredd-useful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-23 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|