flash_extensions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1206d08de232051d056377e51e2cdb15c0740c9d
4
+ data.tar.gz: 3ed1025dfb5654afd9c6efe8eea9d3c14fef1597
5
+ SHA512:
6
+ metadata.gz: 70b7bbee74fdbcf62f92cfca23349f8d40276e884e7b08878d21f8fcf9300319276a390385d512a75244e4ff7c7c594a6447e0daffbd3b1485454e620ca75094
7
+ data.tar.gz: d3a13451ba04b48120a9debd96cabbbe2898c36adea59b5eebfa9819e3d28cf7ca94320b5f830bbd2d796e8edd2e8b7f8fe2e37b39abbcf039230a9d98a95a78
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --order random
2
+ --colour
3
+ --backtrace
4
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ cache: bundler
2
+ language: ruby
3
+ notifications:
4
+ email:
5
+ recipients:
6
+ - j.gomez@drexed.com
7
+ on_failure: change
8
+ on_success: never
9
+ rvm:
10
+ - '2.1.0'
11
+ - '2.0.0'
12
+ - '1.9.3'
13
+ - ruby-head
14
+ script: 'bundle exec rake'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flash_extenstions.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Juan Gomez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,408 @@
1
+ # FlashExtensions
2
+
3
+ [![Build Status](https://travis-ci.org/drexed/flash_extensions.svg?branch=master)](https://travis-ci.org/drexed/flash_extensions)
4
+ [![Coverage Status](https://coveralls.io/repos/drexed/flash_extensions/badge.png)](https://coveralls.io/r/drexed/flash_extensions)
5
+ [![Code Climate](https://codeclimate.com/github/drexed/flash_extensions.png)](https://codeclimate.com/github/drexed/flash_extensions)
6
+
7
+ Flash Extensions is a collection of commonly used object helpers in a ruby based project. It currently includes extensions for: arrays, hash, objects, strings, and time.
8
+
9
+ `Rails Safe` = methods extracted from rails but that do not override that rails method.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'flash_extensions'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install flash_extensions
24
+
25
+ ## Usage
26
+
27
+ ### ArrayExtensions
28
+
29
+ ####Remove Blanks:####
30
+ Use the `remove_blanks` method removes blank elements from an array.
31
+
32
+ ```ruby
33
+ ["this", "", "that", nil].remove_blanks => ["this", "that"]
34
+ "this is a test".split(" ").remove_blanks => ["this", "is", "a", "test"]
35
+ ```
36
+
37
+ ####Remove First Element:####
38
+ Use the `remove_first_element` method removes the first element from an array. Like Array.shift, but returns the array instead of removed the element.
39
+
40
+ ```ruby
41
+ ["1", "2", "3"].remove_first_element => ["2", "3"]
42
+ ```
43
+
44
+ ####Remove Last Element:####
45
+ Use the `remove_last_element` method removes the last element from an array. Like Array.pop, but returns the array instead of removed the element.
46
+
47
+ ```ruby
48
+ ["1", "2", "3"].remove_last_element => ["1", "2"]
49
+ ```
50
+
51
+ ### HashExtensions
52
+
53
+ ####Rename Keys:####
54
+ Use the `rename_keys` method to rename the keys of a hash.
55
+
56
+ ```ruby
57
+ { foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) => { bar: 'foo', baz: 'baz' }
58
+ { foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick') => { bar: 'foo', tick: 'baz' }
59
+ ```
60
+
61
+ ####Stringify Keys:####
62
+ Use the `stringify_keys` and `stringify_keys!` method to convert the hash keys to strings. `Rails Safe`
63
+
64
+ ```ruby
65
+ { foo: 'foo', 'bar' => 'bar' }.stringify_keys => { 'foo' => 'foo', 'baz' => 'baz' }
66
+ ```
67
+
68
+ ####Symbolize Keys:####
69
+ Use the `symbolize_keys` and `symbolize_keys!` method to convert the hash keys to symbols. `Rails Safe`
70
+
71
+ ```ruby
72
+ { foo: 'foo', 'bar' => 'bar' }.symbolize_keys => { foo: 'foo', baz: 'baz' }
73
+ ```
74
+
75
+ ####Symbolize and Underscore Keys:####
76
+ Use the `symbolize_and_underscore_keys` and `symbolize_and_underscore_keys!` method to symbolize and underscore keys.
77
+
78
+ ```ruby
79
+ { 'firstName' => 'example', lastName: 'string' }.symbolize_and_underscore_keys => { first_name: 'foo', last_name: 'test' }
80
+ ```
81
+
82
+ ### ObjectExtensions
83
+
84
+ ####Blank:####
85
+ Use the `blank?` method on a object to determine if it is empty or nil. `Rails Safe`
86
+
87
+ ```ruby
88
+ "".blank? => true
89
+ "Awesome Sting".blank? => false
90
+ ```
91
+
92
+ ####Present:####
93
+ Use the `present?` method on a object to determine if it is not empty or nil. `Rails Safe`
94
+
95
+ ```ruby
96
+ "Awesome Sting".blank? => true
97
+ "".present? => false
98
+ ```
99
+
100
+ ####Numeric:####
101
+ Use the `numeric?` method to determine whether an object's to_s value is numeric.
102
+
103
+ ```ruby
104
+ "-32.50".numeric? => true
105
+ "$2.55".numeric? => false
106
+ ```
107
+
108
+ ####Palindrome:####
109
+ Use the `palindrome?` method to determine if an object is a palindrome.
110
+
111
+ ```ruby
112
+ "racecar".palindrome? => true
113
+ 12321.palindrome? => true
114
+ "example".palindrome? => false
115
+ 12345.palindrome? => false
116
+ ```
117
+
118
+ ####Try:####
119
+ Use the `try` method on a object to try that method with out raising an error. `Rails Safe`
120
+
121
+ ```ruby
122
+ "example".try(:upcase) => "EXAMPLE"
123
+ "example".try(:fake_method) => nil
124
+ ```
125
+
126
+ ### StringExtensions
127
+
128
+ ####Camelize:####
129
+ Use the `camelize` method to transfrom a string to camelcase. `Rails Safe`
130
+
131
+ ```ruby
132
+ "example_string".camelize => "ExampleString"
133
+ "example_string".camelize(:lower) => "exampleString"
134
+ ```
135
+
136
+ ####Ends With:####
137
+ Use the `ends_with?` method to determine whether a string ends with a certain value. `Rails Safe`
138
+
139
+ ```ruby
140
+ "example string".ends_with?("g") => true
141
+ "example string".ends_with?("ng") => true
142
+ "example string".ends_with?("e") => false
143
+ ```
144
+
145
+ ####Starts With:####
146
+ Use the `starts_with?` method to determine whether a string starts with a certain value. `Rails Safe`
147
+
148
+ ```ruby
149
+ "example string".starts_with?("e") => true
150
+ "example string".starts_with?("ex") => true
151
+ "example string".starts_with?("g") => false
152
+ ```
153
+
154
+ ####Humanize:####
155
+ Use the `humanize` method to transform a string to a human readable string. `Rails Safe`
156
+
157
+ ```ruby
158
+ "ExampleString".humanize => "Example string"
159
+ "example_string".humanize => "Example string"
160
+ ```
161
+
162
+ ####Titleize:####
163
+ Use the `titleize` method to capitalize each word in a string. `Rails Safe`
164
+
165
+ ```ruby
166
+ "example string".titleize => "Example String"
167
+ "example_string".titleize => "Example String"
168
+ "ExampleString".titleize => "Example String"
169
+ ```
170
+
171
+ ####Underscore:####
172
+ Use the `underscore` method to transform a string to snakecase. `Rails Safe`
173
+
174
+ ```ruby
175
+ "ExampleString".underscore => "example_string"
176
+ "exampleString".underscore => "example_string"
177
+ ```
178
+
179
+ ####Domain:####
180
+ Use the `domain` method to extract the domain name from a URL.
181
+
182
+ ```ruby
183
+ "http://www.example.com/fake-page".domain => "www.example.com"
184
+ ```
185
+
186
+ ####Downcase:####
187
+ Use the `downcase?` method to determine if all characters are lowercase.
188
+
189
+ ```ruby
190
+ "example".downcase? => true
191
+ "Example".downcase? => false
192
+ "EXAMPLE".downcase? => false
193
+ ```
194
+
195
+ ####Upcase:####
196
+ Use the `upcase?` method to determine if all characters are uppercase.
197
+
198
+ ```ruby
199
+ "EXAMPLE".upcase? => true
200
+ "example".upcase? => false
201
+ "Example".upcase? => false
202
+ ```
203
+
204
+ ####Mixcase:####
205
+ Use the `mixcase?` method to determine if characters are mixedcase.
206
+
207
+ ```ruby
208
+ "Example".mixedcase? => true
209
+ "EXAMPLE".mixedcase? => false
210
+ "example".mixedcase? => false
211
+ ```
212
+
213
+ ####Ellipsize:####
214
+ Use the `ellipsize` method to truncate a string in the middle.
215
+
216
+ **Options**
217
+ * Length: default to 30
218
+ * Offset: default to 4
219
+ * Separator: default to "..."
220
+
221
+ ```ruby
222
+ "example string".ellipsize => "example string"
223
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize => "0123...WXYZ"
224
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ellipsize(offset: 2, separator: "+++") => "01+++YZ"
225
+ ```
226
+
227
+ ####Nix:####
228
+ Use the `nix` method to remove the first instance of a string.
229
+
230
+ ```ruby
231
+ "this thing that thing".nix("thing") => "this that thing"
232
+ ```
233
+
234
+ ####GNix:####
235
+ Use the `gnix` method to remove the every instance of a string.
236
+
237
+ ```ruby
238
+ "this thing that thing".gnix("thing") => "this that "
239
+ ```
240
+
241
+ ####Pollute:####
242
+ 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
+
244
+ ```ruby
245
+ "test".pollute => "t^--^--^e^--^--^s^--^--^t^--^--^"
246
+ "test".pollute("-") => "t-e-s-t-"
247
+ ```
248
+
249
+ ####Unpollute:####
250
+ Use the `unpollute` to remove the default or custom pollution character. Can also be used to remove an unwanted character.
251
+
252
+ ```ruby
253
+ "t^--^--^e^--^--^s^--^--^t^--^--^".unpollute => "test"
254
+ "t-e-s-t-".unpollute => "test"
255
+ ```
256
+
257
+ ####Slugify:####
258
+ Use the `slugify` method to generate a permalink-style string, with odd characters removed.
259
+
260
+ ```ruby
261
+ "example".slugify => "example"
262
+ "example string".slugify => "example-string"
263
+ "Example string @@@ test!".slugify => "example-string-test"
264
+ ```
265
+
266
+ ####Strip Tags:####
267
+ Use the `strip_tags` method to remove HTML tags from a string.
268
+
269
+ ```ruby
270
+ "example".strip_tags => "example"
271
+ "<a href='http://example.com'>click</a>".strip_tags => "click"
272
+ "this is <b>bold</b> and <em>emphatic</em>".strip_tags => "this is bold and emphatic"
273
+ ```
274
+
275
+ ####Strip Whitespace:####
276
+ Use the `strip_whitespace` method removes tab characters and instances of more than one space.
277
+
278
+ ```ruby
279
+ "example string test".strip_whitespace => "example string test"
280
+ " this \t is also a test ".strip_whitespace => "this is also a test"
281
+ ```
282
+
283
+ ####Truncate Preserving Words:####
284
+ Use the `truncate_preserving_words` method to truncate a string while preserving words.
285
+
286
+ **Options**
287
+ * max_words: default to nil
288
+ * max_characters: default to 30
289
+ * Separator: default to "..."
290
+
291
+ ```ruby
292
+ "example string".truncate_preserving_words => "example string"
293
+ "example string test another1 another2 another3".truncate_preserving_words => "example string test another1 ..."
294
+ "example string test another1 another2 another3".truncate_preserving_words(max_chars: 10, separator: "+++") => "example +++"
295
+ ```
296
+
297
+ ### TimeExtensions
298
+
299
+ ####Format:####
300
+ Use the `format` method on a Date or Time object to format it using a human readable string.
301
+
302
+ **Rules**
303
+ * Characters: a-z 0-9 _
304
+ * Characters can only be used to generate a format part
305
+
306
+ ```ruby
307
+ Time.now.format("year") => "2014"
308
+ Time.now.format("month_name day, year hour:minute ampm") => "January 09, 2014 02:31 pm"
309
+ ```
310
+
311
+ | Name | Key | Equivalent `strftime` | Result |
312
+ | --- | --- | --- | --- |
313
+ | Month - digits zero-padded | `m` or `month` or `month_zero` | %m | (01..12) |
314
+ | Month - digits unpadded | `mm` or `Month` or `month_unpadded` | %-m | (1..12) |
315
+ | Month - digits blank-padded | `mmm` or `MONTH` or `day_blank` | %_m | ( 1..12) |
316
+ | Month - name | `mmmm` or `month_name` | %B | January |
317
+ | Month - name abbreviated | `mmmmm` or `month_name_abbr` | %b | Jan |
318
+ | Day - digits zero-padded | `d` or `day` or `day_zero` | %d | (01..31) |
319
+ | Day - digits unpadded | `dd` or `Day` or `day_unpadded` | %-d | (1..31) |
320
+ | Day - digits blank-padded | `ddd` or `DAY` or `day_blank` | %_d | ( 1..31) |
321
+ | Day - digits of the year | `dddd` or `day_of_the_year` | %j | (001..366) |
322
+ | Week - starting monday | `wwwww` or `week` | %M | (00..53) |
323
+ | Week - starting sunday | `wwwwww` or `weekday_offset` | %M | (00..53) |
324
+ | Weekday - starting monday | `w` or `weekday` | %M | (1..7) |
325
+ | Weekday - starting sunday | `ww` or `weekday` | %M | (0..6) |
326
+ | Weekday - name | `www` or `weekday_name` | %M | Sunday |
327
+ | Weekday - name abbreviated | `wwww` or `weekday_name_abbr` | %M | Sun |
328
+ | Year - digits two | `yy` or `yr` | %y | (00..99) |
329
+ | Year - digits four | `yyyy` or `year` | %Y | 1999 |
330
+ | Hour - digits zero-padded | `h` or `hour` or `hour_zero` | %H | (00..23) |
331
+ | Hour - digits blank-padded | `hh` or `HOUR` or `hour_blank` | %k | ( 0..23) |
332
+ | Hour - digits zero-padded | `hhh` or `hour_imperical` or `hour_imperical_zero` | %I | (01..12) |
333
+ | Hour - digits blank-padded | `hhhh` or `HOUR_IMPERICAL` or `hour_imperical_blank` | %l | ( 1..12) |
334
+ | Minute - minute | `n` or `minute` | %M | (00..59) |
335
+ | Second - second | `s` or `second` | %S | (00..60) |
336
+ | Meridian - lowercase | `ampm` or `meridian` | %p | am..pm |
337
+ | Meridian - uppercase | `AMPM` or `MERIDIAN` | %P | AM..PM |
338
+ | Time Zone - time zone | `z` or `time_zone` | %z | +0900 |
339
+ | Time Zone - hour and minute offset | `zz` or `time_zone_offset` | %z | +09:00 |
340
+ | Time Zone - hour, minute and second offset | `zzz` or `time_zone_offset_full` | %z | +09:00:00 |
341
+
342
+ ####To Format:####
343
+ Use the `to_format` method on a Date or Time object to format it without having to use `strftime` method.
344
+
345
+ ```ruby
346
+ Time.now.to_format(:year) => "2014"
347
+ Time.now.to_format(:datetime) => "January 09, 2014 02:31 pm"
348
+ ```
349
+
350
+ | Name | Key | Equivalent `strftime` | Result |
351
+ | --- | --- | --- | --- |
352
+ | Month - digits zero-padded | `:month` or `:month_zero` | %A | (01..31) |
353
+ | Month - digits unpadded | `:month_unpadded` | %a | (1..31) |
354
+ | Month - digits blank-padded | `:month_blank` | %a | ( 1..31) |
355
+ | Month - name | `:month_name` | %A | January |
356
+ | Month - name abbreviated | `:month_name_abbr` | %a | Jan |
357
+ | Weekday - digits zero-padded | `:Weekday_zero` | %A | (01..12) |
358
+ | Weekday - digits unpadded | `:Weekday_unpadded` | %a | (1..12) |
359
+ | Weekday - digits blank-padded | `:Weekday_blank` | %a | ( 1..12) |
360
+ | Weekday - name | `:weekday_name` | %A | Sunday |
361
+ | Weekday - name abbreviated | `:Weekday_name_abbr` | %a | Sun |
362
+ | Year - digits two | `:yr` | %y | (00..99) |
363
+ | Year - digits four | `:year` | %Y | 1999 |
364
+ | Hour - digits zero-padded | `:hour` or `:hour_zero` | %H | (00..23) |
365
+ | Hour - digits blank-padded | `:hour_blank` | %k | ( 0..23) |
366
+ | Hour - digits zero-padded imperical | `:hour_imperical_zero` | %I | (01..12) |
367
+ | Hour - digits blank-padded imperical | `:hour_imperical_blank` | %l | ( 1..12) |
368
+ | Minute - minute | `:minute` | %M | (00..59) |
369
+ | Second - second | `:second` | %S | (00..60) |
370
+ | Time Zone - time zone | `:time_zone` | %z | +0900 |
371
+ | Time Zone - hour and minute offset | `:time_zone_offset` | %z | +09:00 |
372
+ | Time Zone - hour, minute and second offset | `:time_zone_offset_full` | %z | +09:00:00 |
373
+ | Date - name | `:date` | %B %-d, %Y | January 9, 2014 |
374
+ | Date - name abbreviated | `:date_abbr` | %b %-d, %Y | Jan 9, 2014 |
375
+ | Date - iso | `:date_iso` | %Y-%m-%d | 2014-01-09 |
376
+ | Datetime - name | `:datetime` | %B %-d, %Y %H:%M | January 9, 2014 00:31 |
377
+ | Datetime - name abbreviated | `:datetime_abbr` | %b %-d, %Y %H:%M | Jan 9, 2014 00:31 |
378
+ | Datetime - iso | `:datetime_iso` | %Y-%m-%d %H:%M | 2014-01-09 00:31 |
379
+ | Datetime - name imperical | `:datetime_imperical` | %B %-d, %Y %H:%M | January 9, 2014 12:31 am |
380
+ | Datetime - name abbreviated imperical | `:datetime_imperical_abbr` | %b %-d, %Y %H:%M | Jan 9, 2014 12:31 am |
381
+ | Datetime - iso imperical | `:datetime_imperical_iso` | %Y-%m-%d %H:%M | 2014-01-09 12:31 am |
382
+ | Datetime - name time zone | `:datetime_tzn` | %B %-d, %Y %H:%M %Z | January 9, 2014 00:31 UTC |
383
+ | Datetime - name abbreviated time zone | `:datetime_abbr_tzn` | %b %-d, %Y %H:%M %Z | Jan 9, 2014 00:31 UTC |
384
+ | Datetime - iso time zone | `:datetime_iso_tzn` | %Y-%m-%d %H:%M %z | 2014-01-09 00:31 +0000 |
385
+ | Datetime - name imperical time zone | `:datetime_imperical_tzn` | %B %-d, %Y %H:%M %Z | January 9, 2014 12:31 am UTC |
386
+ | Datetime - name abbreviated imperical time zone | `:datetime_imperical_abbr_tzn` | %b %-d, %Y %H:%M %Z | Jan 9, 2014 12:31 am UTC |
387
+ | Datetime - iso imperical time zone | `:datetime_imperical_iso_tzn` | %Y-%m-%d %H:%M %z | 2014-01-09 12:31 am +0000 |
388
+ | Day - name | `:day` | %B %-d | January 9 |
389
+ | Day - name abbreviated | `:day_abbr` | %b %-d | Jan 9 |
390
+ | Day - iso | `:day_iso` | %m-%d | 01-09 |
391
+ | Daytime - name | `:daytime` | %B %-d %H:%M | January 9 00:31 |
392
+ | Daytime - name abbreviated | `:daytime_abbr` | %b %-d %H:%M | Jan 9 00:31 |
393
+ | Daytime - iso | `:daytime_iso` | %m-%d %H:%M | 01-09 00:31 |
394
+ | Daytime - name imperical | `:daytime_imperical` | %B %-d %H:%M | January 9 12:31 am |
395
+ | Daytime - name abbreviated imperical | `:daytime_imperical_abbr` | %b %-d %H:%M | Jan 9 12:31 am |
396
+ | Daytime - iso imperical | `:daytime_imperical_iso` | %m-%d %H:%M | 01-09 12:31 am |
397
+ | Time - zero-padded | `:time` or `:time_zero` | %H:%M | 00:31 |
398
+ | Time - blank-padded | `:time_blank` | %k:%M %z | 0:31 |
399
+ | Time - with time zone | `:time_tz` | %H:%M %z | 00:31 +0000 |
400
+ | Time - with time zone name | `:time_tzn` | %H:%M %Z | 00:31 UTC |
401
+
402
+ ## Contributing
403
+
404
+ 1. Fork it ( http://github.com/<my-github-username>/flash_extensions/fork )
405
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
406
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
407
+ 4. Push to the branch (`git push origin my-new-feature`)
408
+ 5. Create new Pull Request