flash_extensions 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/README.md +204 -83
- data/flash_extensions.gemspec +3 -3
- data/lib/flash_extensions.rb +2 -0
- data/lib/flash_extensions/extensions/array_extension.rb +5 -5
- data/lib/flash_extensions/extensions/enumerable_extension.rb +91 -0
- data/lib/flash_extensions/extensions/hash_extension.rb +24 -8
- data/lib/flash_extensions/extensions/numeric_extension.rb +17 -0
- data/lib/flash_extensions/extensions/object_extension.rb +6 -6
- data/lib/flash_extensions/extensions/string_extension.rb +81 -29
- data/lib/flash_extensions/extensions/time_extension.rb +2 -2
- data/lib/flash_extensions/version.rb +1 -1
- data/spec/lib/array_extension_spec.rb +4 -4
- data/spec/lib/enumerable_extension_spec.rb +116 -0
- data/spec/lib/hash_extension_spec.rb +52 -0
- data/spec/lib/numeric_extension_spec.rb +35 -0
- data/spec/lib/object_extension_spec.rb +2 -0
- data/spec/lib/string_extension_spec.rb +104 -1
- data/spec/lib/time_extension_spec.rb +2 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 090b51df243207aecde9635cad2b62d1308fce33
|
4
|
+
data.tar.gz: 48330907ce5b9d46adcf778efbfdfded426f6950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ea8e99ef235da4cf37b1b071e893b69762f2fa5de1a27db2deeb633ff0c32801249b40ce695ac37d9e25e3dc4b53bace5f115c874aaedb27246d38439a7cb7c
|
7
|
+
data.tar.gz: a9bdd4bc914e5ed9daeac0abb464c4fcccdb6fbe48ee435a5cc04e17358d57c732a5458fcb9a1f19b5c87090b043018f720941460eafb928b19fb260ee4084e9
|
data/.travis.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
before_install:
|
2
|
+
- sudo apt-get install libxml2-dev
|
1
3
|
cache: bundler
|
2
4
|
language: ruby
|
3
5
|
notifications:
|
@@ -7,8 +9,5 @@ notifications:
|
|
7
9
|
on_failure: change
|
8
10
|
on_success: never
|
9
11
|
rvm:
|
10
|
-
- '2.1.0'
|
11
|
-
- '2.0.0'
|
12
|
-
- '1.9.3'
|
13
12
|
- ruby-head
|
14
13
|
script: 'bundle exec rake'
|
data/README.md
CHANGED
@@ -4,10 +4,16 @@
|
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/drexed/flash_extensions/badge.png)](https://coveralls.io/r/drexed/flash_extensions)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/drexed/flash_extensions.png)](https://codeclimate.com/github/drexed/flash_extensions)
|
6
6
|
|
7
|
-
Flash Extensions is a collection of commonly used object helpers in a ruby based project. It currently includes extensions for: arrays,
|
7
|
+
Flash Extensions is a collection of commonly used object helpers in a ruby based project. It currently includes extensions for: arrays, enumerables, hashes, numerics, objects, strings, and time.
|
8
8
|
|
9
9
|
`Rails Safe` = methods extracted from rails but that do not override that rails method.
|
10
10
|
|
11
|
+
Highly recommended extensions:
|
12
|
+
* **Hash:** Hashie - https://github.com/intridea/hashie
|
13
|
+
* **String:** Escape Utils - https://github.com/brianmario/escape_utils
|
14
|
+
* **String:** Fast Blank - https://github.com/SamSaffron/fast_blank
|
15
|
+
* **Translation:** Fast Gettext - https://github.com/grosser/fast_gettext
|
16
|
+
|
11
17
|
## Installation
|
12
18
|
|
13
19
|
Add this line to your application's Gemfile:
|
@@ -30,53 +36,142 @@ Or install it yourself as:
|
|
30
36
|
Use the `remove_blanks` method removes blank elements from an array.
|
31
37
|
|
32
38
|
```ruby
|
33
|
-
["this", "", "that", nil].remove_blanks
|
34
|
-
"this is a test".split(" ").remove_blanks
|
39
|
+
["this", "", "that", nil].remove_blanks #=> ["this", "that"]
|
40
|
+
"this is a test".split(" ").remove_blanks #=> ["this", "is", "a", "test"]
|
35
41
|
```
|
36
42
|
|
37
43
|
####Remove First Element:####
|
38
|
-
Use the `
|
44
|
+
Use the `remove_first` method removes the first element from an array. Like Array.shift, but returns the array instead of removed the element.
|
39
45
|
|
40
46
|
```ruby
|
41
|
-
["1", "2", "3"].
|
47
|
+
["1", "2", "3"].remove_first #=> ["2", "3"]
|
42
48
|
```
|
43
49
|
|
44
50
|
####Remove Last Element:####
|
45
|
-
Use the `
|
51
|
+
Use the `remove_last` method removes the last element from an array. Like Array.pop, but returns the array instead of removed the element.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
["1", "2", "3"].remove_last #=> ["1", "2"]
|
55
|
+
```
|
56
|
+
|
57
|
+
### EnumerableExtensions
|
58
|
+
|
59
|
+
####Average:####
|
60
|
+
Use the `average` method to return the average of a collection of numbers.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
[1,2,3].average #=> 2
|
64
|
+
[].average #=> 0
|
65
|
+
[].average(nil) #=> nil
|
66
|
+
```
|
67
|
+
|
68
|
+
####Drop Last:####
|
69
|
+
Use the `drop_last` method to drops the last number of elements of a collection.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
[1,2,3].drop_last(1) #=> [1,2]
|
73
|
+
[].drop_last(3) #=> []
|
74
|
+
```
|
75
|
+
|
76
|
+
####Drop Last While:####
|
77
|
+
Use the `drop_last_while` method to drops the last number of elements of a collection while it meets a criteria.
|
46
78
|
|
47
79
|
```ruby
|
48
|
-
[
|
80
|
+
[1,2,3].drop_last_while(&:odd?) #=> [1,2]
|
81
|
+
[].drop_last_while(&:odd?) #=> []
|
82
|
+
```
|
83
|
+
|
84
|
+
####Exactly:####
|
85
|
+
Use the `excatly?` method to return if there are exactly the number of an element type.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
[1,2,3].excatly?(3) #=> true
|
89
|
+
[1,1,3,3].exactly?(2, &:even?) #=> false
|
90
|
+
[].exactly?(1) #=> false
|
91
|
+
```
|
92
|
+
|
93
|
+
####Several:####
|
94
|
+
Use the `several?` method to return if there are several types of an element.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
[1,2,3].several? #=> true
|
98
|
+
[1,1,3,3].several?(&:even?) #=> false
|
99
|
+
[].several? #=> false
|
100
|
+
```
|
101
|
+
|
102
|
+
####Sum:####
|
103
|
+
Use the `sum` method to to return the sum of a collection of numbers.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
[1,2,3].sum #=> 2
|
107
|
+
[1,2,3,4].sum #=> 2.5
|
108
|
+
[].sum #=> 0
|
109
|
+
[].sum(nil) #=> nil
|
110
|
+
```
|
111
|
+
|
112
|
+
####Take Last:####
|
113
|
+
Use the `take_last` method to return the last number of elements of a collection.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
[1,2,3].take_last(2) #=> [2,3]
|
117
|
+
[].take_last(3) #=> []
|
118
|
+
```
|
119
|
+
|
120
|
+
####Take Last While:####
|
121
|
+
Use the `take_last_while` method to return the last number of elements of a collection while it meets a criteria.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
[1,2,3,5].take_last_while(&:odd?) #=> [5, 5]
|
125
|
+
[].take_last_while(&:odd?) #=> []
|
49
126
|
```
|
50
127
|
|
51
128
|
### HashExtensions
|
52
129
|
|
130
|
+
####Except:####
|
131
|
+
Use the `except` method to return only key/value pairs not matching certain keys.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
{ foo: 'foo', baz: 'baz', bar: 'bar' }.except(:foo) #=> { baz: 'baz', bar: 'bar' }
|
135
|
+
{ :foo => 'foo', :baz => 'baz', :bar => 'bar' }.except(:baz, :bar) #=> { :foo => 'foo' }
|
136
|
+
{}.except(:foo) #=> {}
|
137
|
+
```
|
138
|
+
|
139
|
+
####Only:####
|
140
|
+
Use the `only` method to return only key/value pairs matching certain keys.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
{ foo: 'foo', baz: 'baz', bar: 'bar' }.only(:foo) #=> { foo: 'foo' }
|
144
|
+
{ :foo => 'foo', :baz => 'baz', :bar => 'bar' }.only(:baz, :bar) #=> { :baz => 'baz', :bar => 'bar' }
|
145
|
+
{}.only(:foo) #=> {}
|
146
|
+
```
|
147
|
+
|
53
148
|
####Rename Keys:####
|
54
|
-
Use the `rename_keys` method to rename the keys of a hash.
|
149
|
+
Use the `rename_keys` and `rename_keys!` method to rename the keys of a hash.
|
55
150
|
|
56
151
|
```ruby
|
57
|
-
{ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar)
|
58
|
-
{ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick')
|
152
|
+
{ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) #=> { bar: 'foo', baz: 'baz' }
|
153
|
+
{ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
|
59
154
|
```
|
60
155
|
|
61
156
|
####Stringify Keys:####
|
62
157
|
Use the `stringify_keys` and `stringify_keys!` method to convert the hash keys to strings. `Rails Safe`
|
63
158
|
|
64
159
|
```ruby
|
65
|
-
{ foo: 'foo', 'bar' => 'bar' }.stringify_keys
|
160
|
+
{ foo: 'foo', 'bar' => 'bar' }.stringify_keys #=> { 'foo' => 'foo', 'baz' => 'baz' }
|
66
161
|
```
|
67
162
|
|
68
163
|
####Symbolize Keys:####
|
69
164
|
Use the `symbolize_keys` and `symbolize_keys!` method to convert the hash keys to symbols. `Rails Safe`
|
70
165
|
|
71
166
|
```ruby
|
72
|
-
{ foo: 'foo', 'bar' => 'bar' }.symbolize_keys
|
167
|
+
{ foo: 'foo', 'bar' => 'bar' }.symbolize_keys #=> { foo: 'foo', baz: 'baz' }
|
73
168
|
```
|
74
169
|
|
75
170
|
####Symbolize and Underscore Keys:####
|
76
171
|
Use the `symbolize_and_underscore_keys` and `symbolize_and_underscore_keys!` method to symbolize and underscore keys.
|
77
172
|
|
78
173
|
```ruby
|
79
|
-
{ 'firstName' => 'example', lastName: 'string' }.symbolize_and_underscore_keys
|
174
|
+
{ 'firstName' => 'example', lastName: 'string' }.symbolize_and_underscore_keys #=> { first_name: 'foo', last_name: 'test' }
|
80
175
|
```
|
81
176
|
|
82
177
|
### ObjectExtensions
|
@@ -85,129 +180,155 @@ Use the `symbolize_and_underscore_keys` and `symbolize_and_underscore_keys!` met
|
|
85
180
|
Use the `blank?` method on a object to determine if it is empty or nil. `Rails Safe`
|
86
181
|
|
87
182
|
```ruby
|
88
|
-
"".blank?
|
89
|
-
"Awesome Sting".blank?
|
183
|
+
"".blank? #=> true
|
184
|
+
"Awesome Sting".blank? #=> false
|
90
185
|
```
|
91
186
|
|
92
187
|
####Present:####
|
93
188
|
Use the `present?` method on a object to determine if it is not empty or nil. `Rails Safe`
|
94
189
|
|
95
190
|
```ruby
|
96
|
-
"Awesome Sting".blank?
|
97
|
-
"".present?
|
191
|
+
"Awesome Sting".blank? #=> true
|
192
|
+
"".present? #=> false
|
98
193
|
```
|
99
194
|
|
100
195
|
####Numeric:####
|
101
196
|
Use the `numeric?` method to determine whether an object's to_s value is numeric.
|
102
197
|
|
103
198
|
```ruby
|
104
|
-
"-32.50".numeric?
|
105
|
-
"$2.55".numeric?
|
199
|
+
"-32.50".numeric? #=> true
|
200
|
+
"$2.55".numeric? #=> false
|
106
201
|
```
|
107
202
|
|
108
203
|
####Palindrome:####
|
109
204
|
Use the `palindrome?` method to determine if an object is a palindrome.
|
110
205
|
|
111
206
|
```ruby
|
112
|
-
"racecar".palindrome?
|
113
|
-
12321.palindrome?
|
114
|
-
"example".palindrome?
|
115
|
-
12345.palindrome?
|
207
|
+
"racecar".palindrome? #=> true
|
208
|
+
12321.palindrome? #=> true
|
209
|
+
"example".palindrome? #=> false
|
210
|
+
12345.palindrome? #=> false
|
116
211
|
```
|
117
212
|
|
118
213
|
####Try:####
|
119
214
|
Use the `try` method on a object to try that method with out raising an error. `Rails Safe`
|
120
215
|
|
121
216
|
```ruby
|
122
|
-
"example".try(:upcase)
|
123
|
-
"example".try(:fake_method)
|
217
|
+
"example".try(:upcase) #=> "EXAMPLE"
|
218
|
+
"example".try(:fake_method) #=> nil
|
219
|
+
```
|
220
|
+
|
221
|
+
### NumericExtensions
|
222
|
+
|
223
|
+
####Multiple Of:####
|
224
|
+
Use the `multiple_of?` method to check if a number is the multiple of another. `Rails Safe`
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
9.multiple_of?(3) #=> true
|
228
|
+
7.multiple_of?(3) #=> false
|
229
|
+
```
|
230
|
+
|
231
|
+
####Negative:####
|
232
|
+
Use the `negative?` method to check if a number is negative.
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
-1.negative? #=> true
|
236
|
+
1.negative? #=> false
|
237
|
+
```
|
238
|
+
|
239
|
+
####Positive:####
|
240
|
+
Use the `positive?` method to check if a number is positive.
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
1.positive? #=> true
|
244
|
+
-1.positive? #=> false
|
124
245
|
```
|
125
246
|
|
126
247
|
### StringExtensions
|
127
248
|
|
128
249
|
####Camelize:####
|
129
|
-
Use the `camelize` method to transfrom a string to camelcase. `Rails Safe`
|
250
|
+
Use the `camelize` and `camelize!` method to transfrom a string to camelcase. `Rails Safe`
|
130
251
|
|
131
252
|
```ruby
|
132
|
-
"example_string".camelize
|
133
|
-
"example_string".camelize(:lower)
|
253
|
+
"example_string".camelize #=> "ExampleString"
|
254
|
+
"example_string".camelize(:lower) #=> "exampleString"
|
134
255
|
```
|
135
256
|
|
136
257
|
####Ends With:####
|
137
258
|
Use the `ends_with?` method to determine whether a string ends with a certain value. `Rails Safe`
|
138
259
|
|
139
260
|
```ruby
|
140
|
-
"example string".ends_with?("g")
|
141
|
-
"example string".ends_with?("ng")
|
142
|
-
"example string".ends_with?("e")
|
261
|
+
"example string".ends_with?("g") #=> true
|
262
|
+
"example string".ends_with?("ng") #=> true
|
263
|
+
"example string".ends_with?("e") #=> false
|
143
264
|
```
|
144
265
|
|
145
266
|
####Starts With:####
|
146
267
|
Use the `starts_with?` method to determine whether a string starts with a certain value. `Rails Safe`
|
147
268
|
|
148
269
|
```ruby
|
149
|
-
"example string".starts_with?("e")
|
150
|
-
"example string".starts_with?("ex")
|
151
|
-
"example string".starts_with?("g")
|
270
|
+
"example string".starts_with?("e") #=> true
|
271
|
+
"example string".starts_with?("ex") #=> true
|
272
|
+
"example string".starts_with?("g") #=> false
|
152
273
|
```
|
153
274
|
|
154
275
|
####Humanize:####
|
155
|
-
Use the `humanize` method to transform a string to a human readable string. `Rails Safe`
|
276
|
+
Use the `humanize` and `humanize!` method to transform a string to a human readable string. `Rails Safe`
|
156
277
|
|
157
278
|
```ruby
|
158
|
-
"ExampleString".humanize
|
159
|
-
"example_string".humanize
|
279
|
+
"ExampleString".humanize #=> "Example string"
|
280
|
+
"example_string".humanize #=> "Example string"
|
160
281
|
```
|
161
282
|
|
162
283
|
####Titleize:####
|
163
|
-
Use the `titleize` method to capitalize each word in a string. `Rails Safe`
|
284
|
+
Use the `titleize` and `titleize!` method to capitalize each word in a string. `Rails Safe`
|
164
285
|
|
165
286
|
```ruby
|
166
|
-
"example string".titleize
|
167
|
-
"example_string".titleize
|
168
|
-
"ExampleString".titleize
|
287
|
+
"example string".titleize #=> "Example String"
|
288
|
+
"example_string".titleize #=> "Example String"
|
289
|
+
"ExampleString".titleize #=> "Example String"
|
169
290
|
```
|
170
291
|
|
171
292
|
####Underscore:####
|
172
|
-
Use the `underscore` method to transform a string to snakecase. `Rails Safe`
|
293
|
+
Use the `underscore` and `underscore!` method to transform a string to snakecase. `Rails Safe`
|
173
294
|
|
174
295
|
```ruby
|
175
|
-
"ExampleString".underscore
|
176
|
-
"exampleString".underscore
|
296
|
+
"ExampleString".underscore #=> "example_string"
|
297
|
+
"exampleString".underscore #=> "example_string"
|
177
298
|
```
|
178
299
|
|
179
300
|
####Domain:####
|
180
301
|
Use the `domain` method to extract the domain name from a URL.
|
181
302
|
|
182
303
|
```ruby
|
183
|
-
"http://www.example.com/fake-page".domain
|
304
|
+
"http://www.example.com/fake-page".domain #=> "www.example.com"
|
184
305
|
```
|
185
306
|
|
186
307
|
####Downcase:####
|
187
308
|
Use the `downcase?` method to determine if all characters are lowercase.
|
188
309
|
|
189
310
|
```ruby
|
190
|
-
"example".downcase?
|
191
|
-
"Example".downcase?
|
192
|
-
"EXAMPLE".downcase?
|
311
|
+
"example".downcase? #=> true
|
312
|
+
"Example".downcase? #=> false
|
313
|
+
"EXAMPLE".downcase? #=> false
|
193
314
|
```
|
194
315
|
|
195
316
|
####Upcase:####
|
196
317
|
Use the `upcase?` method to determine if all characters are uppercase.
|
197
318
|
|
198
319
|
```ruby
|
199
|
-
"EXAMPLE".upcase?
|
200
|
-
"example".upcase?
|
201
|
-
"Example".upcase?
|
320
|
+
"EXAMPLE".upcase? #=> true
|
321
|
+
"example".upcase? #=> false
|
322
|
+
"Example".upcase? #=> false
|
202
323
|
```
|
203
324
|
|
204
325
|
####Mixcase:####
|
205
326
|
Use the `mixcase?` method to determine if characters are mixedcase.
|
206
327
|
|
207
328
|
```ruby
|
208
|
-
"Example".mixedcase?
|
209
|
-
"EXAMPLE".mixedcase?
|
210
|
-
"example".mixedcase?
|
329
|
+
"Example".mixedcase? #=> true
|
330
|
+
"EXAMPLE".mixedcase? #=> false
|
331
|
+
"example".mixedcase? #=> false
|
211
332
|
```
|
212
333
|
|
213
334
|
####Ellipsize:####
|
@@ -219,65 +340,65 @@ Use the `ellipsize` method to truncate a string in the middle.
|
|
219
340
|
* Separator: default to "..."
|
220
341
|
|
221
342
|
```ruby
|
222
|
-
"example string".ellipsize
|
223
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize
|
224
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(offset: 2, separator: "+++")
|
343
|
+
"example string".ellipsize #=> "example string"
|
344
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize #=> "0123...WXYZ"
|
345
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(offset: 2, separator: "+++") #=> "01+++YZ"
|
225
346
|
```
|
226
347
|
|
227
348
|
####Nix:####
|
228
|
-
Use the `nix` method to remove the first instance of a string.
|
349
|
+
Use the `nix` and `nix!` method to remove the first instance of a string.
|
229
350
|
|
230
351
|
```ruby
|
231
|
-
"this thing that thing".nix("thing")
|
352
|
+
"this thing that thing".nix("thing") #=> "this that thing"
|
232
353
|
```
|
233
354
|
|
234
355
|
####GNix:####
|
235
|
-
Use the `gnix` method to remove the every instance of a string.
|
356
|
+
Use the `gnix` and `gnix!` method to remove the every instance of a string.
|
236
357
|
|
237
358
|
```ruby
|
238
|
-
"this thing that thing".gnix("thing")
|
359
|
+
"this thing that thing".gnix("thing") #=> "this that "
|
239
360
|
```
|
240
361
|
|
241
362
|
####Pollute:####
|
242
363
|
Use the `pollute` method to pollute the space between every letter in a string, so it will be exempt from any impending string searches.
|
243
364
|
|
244
365
|
```ruby
|
245
|
-
"test".pollute
|
246
|
-
"test".pollute("-")
|
366
|
+
"test".pollute #=> "t^--^--^e^--^--^s^--^--^t^--^--^"
|
367
|
+
"test".pollute("-") #=> "t-e-s-t-"
|
247
368
|
```
|
248
369
|
|
249
370
|
####Unpollute:####
|
250
371
|
Use the `unpollute` to remove the default or custom pollution character. Can also be used to remove an unwanted character.
|
251
372
|
|
252
373
|
```ruby
|
253
|
-
"t^--^--^e^--^--^s^--^--^t^--^--^".unpollute
|
254
|
-
"t-e-s-t-".unpollute
|
374
|
+
"t^--^--^e^--^--^s^--^--^t^--^--^".unpollute #=> "test"
|
375
|
+
"t-e-s-t-".unpollute #=> "test"
|
255
376
|
```
|
256
377
|
|
257
378
|
####Slugify:####
|
258
|
-
Use the `slugify` method to generate a permalink-style string, with odd characters removed.
|
379
|
+
Use the `slugify` and `slugify!` method to generate a permalink-style string, with odd characters removed.
|
259
380
|
|
260
381
|
```ruby
|
261
|
-
"example".slugify
|
262
|
-
"example string".slugify
|
263
|
-
"Example string @@@ test!".slugify
|
382
|
+
"example".slugify #=> "example"
|
383
|
+
"example string".slugify #=> "example-string"
|
384
|
+
"Example string @@@ test!".slugify #=> "example-string-test"
|
264
385
|
```
|
265
386
|
|
266
387
|
####Strip Tags:####
|
267
|
-
Use the `strip_tags` method to remove HTML tags from a string.
|
388
|
+
Use the `strip_tags` and `strip_tags!` method to remove HTML tags from a string.
|
268
389
|
|
269
390
|
```ruby
|
270
|
-
"example".strip_tags
|
271
|
-
"<a href='http://example.com'>click</a>".strip_tags
|
272
|
-
"this is <b>bold</b> and <em>emphatic</em>".strip_tags
|
391
|
+
"example".strip_tags #=> "example"
|
392
|
+
"<a href='http://example.com'>click</a>".strip_tags #=> "click"
|
393
|
+
"this is <b>bold</b> and <em>emphatic</em>".strip_tags #=> "this is bold and emphatic"
|
273
394
|
```
|
274
395
|
|
275
396
|
####Strip Whitespace:####
|
276
|
-
Use the `strip_whitespace` method removes tab characters and instances of more than one space.
|
397
|
+
Use the `strip_whitespace` and `strip_whitespace!` method removes tab characters and instances of more than one space.
|
277
398
|
|
278
399
|
```ruby
|
279
|
-
"example string test".strip_whitespace
|
280
|
-
" this \t is also a test ".strip_whitespace
|
400
|
+
"example string test".strip_whitespace #=> "example string test"
|
401
|
+
" this \t is also a test ".strip_whitespace #=> "this is also a test"
|
281
402
|
```
|
282
403
|
|
283
404
|
####Truncate Preserving Words:####
|
@@ -289,9 +410,9 @@ Use the `truncate_preserving_words` method to truncate a string while preserving
|
|
289
410
|
* Separator: default to "..."
|
290
411
|
|
291
412
|
```ruby
|
292
|
-
"example string".truncate_preserving_words
|
293
|
-
"example string test another1 another2 another3".truncate_preserving_words
|
294
|
-
"example string test another1 another2 another3".truncate_preserving_words(max_chars: 10, separator: "+++")
|
413
|
+
"example string".truncate_preserving_words #=> "example string"
|
414
|
+
"example string test another1 another2 another3".truncate_preserving_words #=> "example string test another1 ..."
|
415
|
+
"example string test another1 another2 another3".truncate_preserving_words(max_chars: 10, separator: "+++") #=> "example +++"
|
295
416
|
```
|
296
417
|
|
297
418
|
### TimeExtensions
|
@@ -304,8 +425,8 @@ Use the `format` method on a Date or Time object to format it using a human read
|
|
304
425
|
* Characters can only be used to generate a format part
|
305
426
|
|
306
427
|
```ruby
|
307
|
-
Time.now.format("year")
|
308
|
-
Time.now.format("month_name day, year hour:minute ampm")
|
428
|
+
Time.now.format("year") #=> "2014"
|
429
|
+
Time.now.format("month_name day, year hour:minute ampm") #=> "January 09, 2014 02:31 pm"
|
309
430
|
```
|
310
431
|
|
311
432
|
| Name | Key | Equivalent `strftime` | Result |
|
@@ -343,8 +464,8 @@ Time.now.format("month_name day, year hour:minute ampm") => "January 09, 2014 02
|
|
343
464
|
Use the `to_format` method on a Date or Time object to format it without having to use `strftime` method.
|
344
465
|
|
345
466
|
```ruby
|
346
|
-
Time.now.to_format(:year)
|
347
|
-
Time.now.to_format(:datetime)
|
467
|
+
Time.now.to_format(:year) #=> "2014"
|
468
|
+
Time.now.to_format(:datetime) #=> "January 09, 2014 02:31 pm"
|
348
469
|
```
|
349
470
|
|
350
471
|
| Name | Key | Equivalent `strftime` | Result |
|