active_object 2.4.0 → 2.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c5a0cc75ea528f9f8d9c335251e73ee6b028df9
4
- data.tar.gz: f35fc893582d7f3cec67f75c4460c8d9b07e86b4
3
+ metadata.gz: fd289204015cf2665adbdb3c6bd2f3518580040e
4
+ data.tar.gz: c6a99671c57f9b480ef81d971d4de1df751daf47
5
5
  SHA512:
6
- metadata.gz: ef2bd8a4ea89bd6ac270e4782174e62efbe028c05710edd4403aa0a43971d16b7856171b865accd34c1c96aaa6b2bc99e9289324f978b9bb31c78751883d4a5e
7
- data.tar.gz: 7fbb6a45bed71c87fe3168e772638f511090130b15d195b1a1a361bb866be2390b34572d042e09e15a0c1144280ecd0f44e2d45f80c652f961d5d9e682c529e2
6
+ metadata.gz: f3f05c2f18bf9a56e71e27a40fa7df4b4f0413c27e348cc833e2a3c9b72fbe3f25eac5ca1836c3b79bc64113b4e233aa6e9b0f9b183d297950a7cb090ce38d88
7
+ data.tar.gz: a3dc7de58f5775c25e533769ca998d03f997a30f3971b02e9bca384427ebe6e28e239abcacf84189a1314dd606e85be0f29e56bf620538f89bfa73504d484397
data/README.md CHANGED
@@ -1518,6 +1518,15 @@ false.truthy? #=> false
1518
1518
  "example".indent(2, "\t") #=> "\t\texample"
1519
1519
  ```
1520
1520
 
1521
+ ####Index all:####
1522
+ `index_all` returns the index values of matching patterns.
1523
+
1524
+ ```ruby
1525
+ "012324507654301243".index_all(0) #=> [0,7,13]
1526
+ "the apple is the best fruit in the world".index_all("the") #=> [0,13,31]
1527
+ "asdfasdfasdf".index_all(/sd/) #=> [1,5,9]
1528
+ ```
1529
+
1521
1530
  ####Labelize:####
1522
1531
  `labelize` and `labelize!` transforms a string to a human readable string.
1523
1532
 
@@ -1581,12 +1590,28 @@ false.truthy? #=> false
1581
1590
  "test".pollute("-") #=> "t-e-s-t-"
1582
1591
  ```
1583
1592
 
1593
+ ####Pop:####
1594
+ `pop` returns the last character of a string.
1595
+
1596
+ ```ruby
1597
+ "test".pop #=> "t"
1598
+ ```
1599
+
1600
+ ####Push:####
1601
+ `push` concats string to self.
1602
+
1603
+ ```ruby
1604
+ "test".push("er") #=> "tester"
1605
+ ```
1606
+
1584
1607
  ####Remove:####
1585
1608
  `remove` and `remove!` removes every instance of a string.
1586
1609
 
1587
1610
  ```ruby
1588
1611
  "this thing that thing".remove("thing") #=> "this that "
1612
+ "this thing that thing".remove(1..3) #=> "t thing that thing"
1589
1613
  "this thing that them".remove("thing", "them") #=> "this that "
1614
+ "this thing that them".remove("thing", 1..3) #=> "t that them"
1590
1615
  ```
1591
1616
 
1592
1617
  ####Remove Tags:####
@@ -1610,6 +1635,7 @@ false.truthy? #=> false
1610
1635
  `shift` and `shift!` removes the first instance of a string.
1611
1636
 
1612
1637
  ```ruby
1638
+ "this thing that thing".shift #=> "t"
1613
1639
  "this thing that thing".shift("thing") #=> "this that thing"
1614
1640
  "this thing that thing".shift("this", "that") #=> " thing thing"
1615
1641
  ```
@@ -1622,6 +1648,15 @@ false.truthy? #=> false
1622
1648
  "ruby rules".sample! #=> "rblse syru"
1623
1649
  ```
1624
1650
 
1651
+ ####Sift:####
1652
+ `sift` and `sift!` returns a string matching any character in a pattern.
1653
+
1654
+ ```ruby
1655
+ "qa2ws3ed4rf5tg6yh7uj8ik9ol".sift("0123456789") #=> "23456789"
1656
+ "qa2ws3ed4rf5tg6yh7uj8ik9ol".sift(0..9) #=> "23456789"
1657
+ "qa2ws3ed4rf5tg6yh7uj8ik9ol".sift([0,1,2,3,4,5,6,7,8,9]) #=> "23456789"
1658
+ ```
1659
+
1625
1660
  ####Slugify:####
1626
1661
  `slugify` and `slugify!` generates a permalink-style string, with odd characters removed.
1627
1662
 
@@ -1631,6 +1666,13 @@ false.truthy? #=> false
1631
1666
  "Example string @@@ test!".slugify #=> "example-string-test"
1632
1667
  ```
1633
1668
 
1669
+ ####Sort:####
1670
+ `sort` and `sort!` sorts a string.
1671
+
1672
+ ```ruby
1673
+ "adbec".sort #=> "abcde"
1674
+ ```
1675
+
1634
1676
  ####Squish:####
1635
1677
  `squish` and `squish!` returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each. `Rails Safe`
1636
1678
 
@@ -1712,6 +1754,14 @@ false.truthy? #=> false
1712
1754
  "Example".upcase? #=> false
1713
1755
  ```
1714
1756
 
1757
+ ####Unshift:####
1758
+ `unshift` and `unshift!` prepends string(s) to self.
1759
+
1760
+ ```ruby
1761
+ "this thing that thing".unshift("thing ") #=> "thing this thing that thing"
1762
+ "this thing that thing".unshift("this ", "that ") #=> "this that this thing that thing"
1763
+ ```
1764
+
1715
1765
  ## Time
1716
1766
 
1717
1767
  *Note:* also works with Date class.
@@ -1823,6 +1873,8 @@ Time.now.stamp(:datetime) #=> "January 09, 2014 02:31 pm"
1823
1873
  | Daytime - iso imperical | `:daytime_imperical_iso` | %m-%d %H:%M | 01-09 12:31 am |
1824
1874
  | Time - zero-padded | `:time` or `:time_padded` | %H:%M | 00:31 |
1825
1875
  | Time - blank-padded | `:time_blank` | %k:%M %z | 0:31 |
1876
+ | Time - zero-padded imperical | `:time_imperical` or `:time_imperical_padded` | %I:%M %P | 07:31 |
1877
+ | Time - blank-padded imperical | `:time_imperical_blank` | %l:%M %P | 7:31 |
1826
1878
  | Time - with time zone | `:time_tz` | %H:%M %z | 00:31 +0000 |
1827
1879
  | Time - with time zone name | `:time_tzn` | %H:%M %Z | 00:31 UTC |
1828
1880
 
@@ -96,11 +96,11 @@ module Enumerable
96
96
  end
97
97
 
98
98
  def max(identity=0)
99
- length > 0 ? sort.last : identity
99
+ (length rescue count) > 0 ? sort.last : identity
100
100
  end
101
101
 
102
102
  def min(identity=0)
103
- length > 0 ? sort.first : identity
103
+ (length rescue count) > 0 ? sort.first : identity
104
104
  end
105
105
 
106
106
  def mean(identity=0)
@@ -160,6 +160,20 @@ class String
160
160
  end
161
161
  end
162
162
 
163
+ def index_all(pattern)
164
+ pattern = pattern.to_s if pattern.is_a?(Numeric)
165
+ arr_indexes = []
166
+ srch_index = rindex(pattern)
167
+
168
+ while srch_index do
169
+ temp_string = self[0..(srch_index - 1)]
170
+ arr_indexes << srch_index
171
+ srch_index = srch_index.zero? ? nil : temp_string.rindex(pattern)
172
+ end
173
+
174
+ arr_indexes.reverse
175
+ end
176
+
163
177
  def labelize(options={})
164
178
  underscore.
165
179
  tr('_'.freeze, ' '.freeze).
@@ -224,10 +238,26 @@ class String
224
238
  replace(pollute(delimiter))
225
239
  end
226
240
 
241
+ def pop
242
+ self[-1]
243
+ end
244
+
245
+ def push(string)
246
+ replace(concat(string))
247
+ end
248
+
227
249
  unless defined?(Rails)
228
250
  def remove(*patterns)
229
251
  string = dup
230
- patterns.flatten.each { |p| string.gsub!(p, ''.freeze) }
252
+
253
+ patterns.flatten.each do |p|
254
+ if p.is_a?(Range)
255
+ string.slice!(p)
256
+ else
257
+ string.gsub!(p, ''.freeze)
258
+ end
259
+ end
260
+
231
261
  string
232
262
  end
233
263
  end
@@ -255,9 +285,13 @@ class String
255
285
  end
256
286
 
257
287
  def shift(*patterns)
258
- string = dup
259
- patterns.flatten.each { |p| string.sub!(p, ''.freeze) }
260
- string
288
+ if patterns.empty?
289
+ self[0]
290
+ else
291
+ string = dup
292
+ patterns.flatten.each { |p| string.sub!(p, ''.freeze) }
293
+ string
294
+ end
261
295
  end
262
296
 
263
297
  def shift!(*patterns)
@@ -272,6 +306,22 @@ class String
272
306
  replace(shuffle(separator))
273
307
  end
274
308
 
309
+ def sift(chars_to_keep)
310
+ chars_to_keep = case chars_to_keep
311
+ when String then chars_to_keep.chars
312
+ when Array then chars_to_keep.map { |c| c.to_s }
313
+ when Range then chars_to_keep.to_a.map { |c| c.to_s }
314
+ else
315
+ raise TypeError, "Invalid parameter"
316
+ end
317
+
318
+ chars.keep_if { |chr| chars_to_keep.include?(chr) }.join
319
+ end
320
+
321
+ def sift!(chars_to_keep)
322
+ replace(sift(chars_to_keep))
323
+ end
324
+
275
325
  def slugify
276
326
  gsub(/[^\x00-\x7F]+/, ''.freeze).
277
327
  gsub(/[^\w_ \-]+/i, ''.freeze).
@@ -297,6 +347,14 @@ class String
297
347
  end
298
348
  end
299
349
 
350
+ def sort
351
+ chars.sort.join
352
+ end
353
+
354
+ def sort!
355
+ replace(sort)
356
+ end
357
+
300
358
  unless defined?(Rails)
301
359
  def titleize
302
360
  underscore.
@@ -379,4 +437,15 @@ class String
379
437
  upcase == self
380
438
  end
381
439
 
440
+ def unshift(*patterns)
441
+ string = ''
442
+ patterns.flatten.each { |p| string.concat(p) }
443
+ string.concat(self)
444
+ string
445
+ end
446
+
447
+ def unshift!(*patterns)
448
+ replace(unshift(*patterns))
449
+ end
450
+
382
451
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveObject
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler