wordnik_ruby_helpers 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordnik_ruby_helpers (0.0.1)
4
+ wordnik_ruby_helpers (0.0.5)
5
5
  RedCloth (>= 4.2.3)
6
- i18n
7
6
  rails
8
7
 
9
8
  GEM
@@ -87,7 +86,6 @@ PLATFORMS
87
86
 
88
87
  DEPENDENCIES
89
88
  RedCloth (>= 4.2.3)
90
- i18n
91
89
  rails
92
90
  rspec
93
91
  wordnik_ruby_helpers!
@@ -93,6 +93,153 @@ module WordnikRubyHelpers
93
93
  items = obj.class.columns.map{ |col| info_pair(col.name, obj[col.name]) }
94
94
  content_tag(:ul, convert_to_list_items(items), :class => "model_columns")
95
95
  end
96
+
97
+ end
98
+ end
99
+
100
+ ActionView::Base.send :include, WordnikRubyHelpers::ViewHelpers if defined?(ActionView)
96
101
 
97
- end
102
+ class Object
103
+
104
+ def numeric?
105
+ !self.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
106
+ end
107
+
98
108
  end
109
+
110
+ class String
111
+
112
+ # Pollute the space between every letter in a string,
113
+ # so it will be exempt from any impending string searches.
114
+ def pollute(delimiter = "^--^--^")
115
+ self.split('').map{|letter| "#{letter}#{delimiter}" }.join
116
+ end
117
+
118
+ # Meant to be paired with the pollute method, this removes 'pollution' from the string
119
+ def sanitize(delimiter = "^--^--^")
120
+ self.gsub(delimiter, "")
121
+ end
122
+
123
+ # Removes the middle from long strings, replacing with a placeholder
124
+ def ellipsize(options={})
125
+ max = options[:max] || 40
126
+ delimiter = options[:delimiter] || "..."
127
+ return self if self.size <= max
128
+ offset = max/2
129
+ self[0,offset] + delimiter + self[-offset,offset]
130
+ end
131
+
132
+ # Generates a permalink-style string, with odd characters removed, etc.
133
+ def permalinkify
134
+ result = self.to_s
135
+ result.gsub!(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
136
+ result.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars.
137
+ result.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row.
138
+ result.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator.
139
+ result.downcase
140
+ end
141
+
142
+ # Removes HTML tags from a string
143
+ def strip_tags
144
+ self.gsub(/<\/?[^>]*>/, "")
145
+ end
146
+
147
+ # Removes first instance of string
148
+ def nix(string)
149
+ self.sub(string, "")
150
+ end
151
+
152
+ # Removes all instances of string
153
+ def gnix(string)
154
+ self.gsub(string, "")
155
+ end
156
+
157
+ # Prepends 'http://' to the beginning of non-empty strings that don't already have it.
158
+ def add_http
159
+ return "" if self.blank?
160
+ return "http://#{self}" unless self.starts_with?("http")
161
+ self
162
+ end
163
+
164
+ # Removes presentationally superflous http and/or www text from the beginning of the string
165
+ def remove_http_and_www
166
+ return "" if self.blank?
167
+ return self.split(".").remove_first_element.join(".") if self.starts_with?("www.")
168
+ self.gsub("http://www.", "").gsub("http://", "").gsub("https://www.", "").gsub("https://", "")
169
+ end
170
+
171
+ # Shortens a string, preserving the last word. Truncation can be limited by words or characters
172
+ def truncate_preserving_words(options={})
173
+ end_string = options[:end_string] || "..."
174
+ max_words = options[:max_words] || nil
175
+ if max_words
176
+ words = self.split()
177
+ return self if words.size < max_words
178
+ words = words[0..(max_words-1)]
179
+ words << end_string
180
+ words.join(" ")
181
+ else
182
+ max_chars = options[:max_chars] || 60
183
+ return self if self.size < max_chars
184
+ out = self[0..(max_chars-1)].split(" ")
185
+ out.pop
186
+ out << end_string
187
+ out.join(" ")
188
+ end
189
+ end
190
+
191
+ # Extracts domain name from a URL
192
+ def domain
193
+ url = self.dup
194
+ url=~(/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : url
195
+ end
196
+
197
+ # Extracts domain name (sans 'www.') from a URL string
198
+ def domain_without_www
199
+ self.domain.remove_http_and_www
200
+ end
201
+
202
+ # Returns true or false depending on whether a string appears to be a URL
203
+ def valid_url?
204
+ !self.match(/https?:\/\/([^\/]+)(.*)/).nil?
205
+ end
206
+
207
+ # Returns true or false depending on whether a string appears to be an email address
208
+ def valid_email?
209
+ !self.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$/i).nil?
210
+ end
211
+
212
+ # Removes tab characters and instances of more than one space
213
+ def remove_whitespace
214
+ self.gnix("\t").split(" ").remove_blanks.join(" ")
215
+ end
216
+
217
+ # Returns true if all letters in the string are capitalized
218
+ def upcase?
219
+ self.upcase == self
220
+ end
221
+
222
+ # Returns true if all letters in the string are lowercase
223
+ def downcase?
224
+ self.downcase == self
225
+ end
226
+
227
+ end
228
+
229
+ class Array
230
+
231
+ def remove_blanks
232
+ self.reject{ |e| e.blank? }
233
+ end
234
+
235
+ # Like Array.shift, but returns the array instead of removed the element.
236
+ def remove_first_element
237
+ self[1..self.size]
238
+ end
239
+
240
+ # Like Array.pop, but returns the array instead of removed the element.
241
+ def remove_last_element
242
+ self[0..self.size-2]
243
+ end
244
+
245
+ end
@@ -1,3 +1,3 @@
1
1
  module WordnikRubyHelpers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Zeke Sikelianos", "John McGrath"]
10
10
  s.email = ["zeke@wordnik.com", "john@wordnik.com"]
11
11
  s.homepage = "http://wordnik.com"
12
- s.summary = %q{A handful of monkey patches and view helpers that we use in our ruby/rails projects}
13
- s.description = %q{A handful of monkey patches and view helpers that we use in our ruby/rails projects}
12
+ s.summary = %q{A handful of monkey patches and view helpers that we use in our rails projects}
13
+ s.description = %q{A handful of monkey patches and view helpers that we use in our rails projects}
14
14
 
15
15
  s.rubyforge_project = "wordnik_ruby_helpers"
16
16
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Zeke Sikelianos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 -08:00
18
+ date: 2011-01-17 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: "0"
60
60
  type: :development
61
61
  version_requirements: *id003
62
- description: A handful of monkey patches and view helpers that we use in our ruby/rails projects
62
+ description: A handful of monkey patches and view helpers that we use in our rails projects
63
63
  email:
64
64
  - zeke@wordnik.com
65
65
  - john@wordnik.com
@@ -75,7 +75,6 @@ files:
75
75
  - Gemfile.lock
76
76
  - README
77
77
  - Rakefile
78
- - init.rb
79
78
  - lib/wordnik_ruby_helpers.rb
80
79
  - lib/wordnik_ruby_helpers/version.rb
81
80
  - spec/spec.opts
@@ -113,7 +112,7 @@ rubyforge_project: wordnik_ruby_helpers
113
112
  rubygems_version: 1.3.7
114
113
  signing_key:
115
114
  specification_version: 3
116
- summary: A handful of monkey patches and view helpers that we use in our ruby/rails projects
115
+ summary: A handful of monkey patches and view helpers that we use in our rails projects
117
116
  test_files:
118
117
  - spec/spec.opts
119
118
  - spec/spec_helper.rb
data/init.rb DELETED
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/lib/wordnik_ruby_helpers'
2
-
3
- # ActionView::Base.send( :include, WordnikRubyHelpers::ViewHelpers )
4
-
5
- ActionController::Base.helper(WordnikRubyHelpers::ViewHelpers)