active_object 2.5.2 → 3.0.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 +4 -4
- data/Gemfile +2 -2
- data/LICENSE.txt +2 -2
- data/README.md +127 -54
- data/active_object.gemspec +5 -4
- data/bin/rake +6 -6
- data/lib/active_object.rb +25 -1
- data/lib/active_object/array.rb +91 -80
- data/lib/active_object/configuration.rb +21 -0
- data/lib/active_object/date.rb +31 -98
- data/lib/active_object/enumerable.rb +20 -26
- data/lib/active_object/hash.rb +73 -94
- data/lib/active_object/integer.rb +8 -17
- data/lib/active_object/numeric.rb +125 -129
- data/lib/active_object/object.rb +19 -25
- data/lib/active_object/range.rb +12 -14
- data/lib/active_object/string.rb +154 -224
- data/lib/active_object/time.rb +54 -146
- data/lib/active_object/version.rb +2 -2
- data/lib/generators/active_object/install_generator.rb +12 -0
- data/lib/generators/active_object/templates/install.rb +12 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 489fe05da332fe9dafa7760f80a0b37c26e17319
|
4
|
+
data.tar.gz: ed2487b328b96c6445b9145513216efbe57d6fdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a3c429d839edc2c86fd50e76c95b77e4b7aa78834626a68addffced3f297909a0804678e5eb7556d259025a11fdb6aee8a674d701a8b4fbf584c71dcddb83a
|
7
|
+
data.tar.gz: 0f4d65fd9dcdf9c957d2495c372b665c3a28029e02725bcf45b033f07fc0412401d0d06323c3a305339d4abbd213ed45107caa488264f134c024b0756e807fb8
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2016 Drexed
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,12 +2,10 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/active_object)
|
4
4
|
[](https://travis-ci.org/drexed/active_object)
|
5
|
-
[](https://coveralls.io/github/drexed/active_object?branch=master)
|
6
6
|
|
7
7
|
ActiveObject is a collection of commonly used object helpers in a ruby based project.
|
8
8
|
|
9
|
-
`Rails Safe` = methods extracted from rails but that do not override that rails method.
|
10
|
-
|
11
9
|
Highly recommended extensions:
|
12
10
|
* **Hash:** Hashie - https://github.com/intridea/hashie
|
13
11
|
* **String:** Escape Utils - https://github.com/brianmario/escape_utils
|
@@ -31,6 +29,7 @@ Or install it yourself as:
|
|
31
29
|
|
32
30
|
## Table of Contents
|
33
31
|
|
32
|
+
* [Configuration](#configuration)
|
34
33
|
* [Array](#array)
|
35
34
|
* [Enumerable](#enumerable)
|
36
35
|
* [Hash](#hash)
|
@@ -41,6 +40,29 @@ Or install it yourself as:
|
|
41
40
|
* [String](#string)
|
42
41
|
* [Time](#time)
|
43
42
|
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
`rails g active_object:install` will generate the following `active_object.rb` file:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# config/initalizers/active_object.rb
|
49
|
+
|
50
|
+
ActiveObject.configure do |config|
|
51
|
+
# option = default
|
52
|
+
|
53
|
+
config.autoload_array = true
|
54
|
+
config.autoload_date = true
|
55
|
+
config.autoload_enumerable = true
|
56
|
+
config.autoload_hash = true
|
57
|
+
config.autoload_integer = true
|
58
|
+
config.autoload_numeric = true
|
59
|
+
config.autoload_object = true
|
60
|
+
config.autoload_range = true
|
61
|
+
config.autoload_string = true
|
62
|
+
config.autoload_time = true
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
44
66
|
## Array
|
45
67
|
|
46
68
|
####After:####
|
@@ -82,6 +104,13 @@ Or install it yourself as:
|
|
82
104
|
[1, 2, 3, 4].delete_values(1, 3) #=> [2, 4]
|
83
105
|
```
|
84
106
|
|
107
|
+
####Dig:####
|
108
|
+
`dig` returns the value of a nested array.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
["zero", ["ten", "eleven", "twelve"], "two"].dig(1, 2) #=> "twelve"
|
112
|
+
```
|
113
|
+
|
85
114
|
####Duplicates:####
|
86
115
|
`duplicates` returns list of duplicate elements.
|
87
116
|
|
@@ -91,7 +120,7 @@ Or install it yourself as:
|
|
91
120
|
```
|
92
121
|
|
93
122
|
####From:####
|
94
|
-
`from` returns the tail of the array from position.
|
123
|
+
`from` returns the tail of the array from position.
|
95
124
|
|
96
125
|
```ruby
|
97
126
|
["1", "2", "3"].from(0) #=> ["1", "2", "3"]
|
@@ -107,7 +136,7 @@ Or install it yourself as:
|
|
107
136
|
```
|
108
137
|
|
109
138
|
####In Groups:####
|
110
|
-
`in_groups` splits or iterates over the array in number of groups, padding any remaining slots with fill_with unless it is false.
|
139
|
+
`in_groups` splits or iterates over the array in number of groups, padding any remaining slots with fill_with unless it is false.
|
111
140
|
|
112
141
|
```ruby
|
113
142
|
%w(1 2 3 4 5 6 7 8 9 10).in_groups(3) #=> [["1", "2", "3", "4"], ["5", "6", "7", nil], ["8", "9", "10", nil]]
|
@@ -116,7 +145,7 @@ Or install it yourself as:
|
|
116
145
|
```
|
117
146
|
|
118
147
|
####In Groups Of:####
|
119
|
-
`in_groups_of` splits or iterates over the array in groups of size number, padding any remaining slots with fill_with unless it is false.
|
148
|
+
`in_groups_of` splits or iterates over the array in groups of size number, padding any remaining slots with fill_with unless it is false.
|
120
149
|
|
121
150
|
```ruby
|
122
151
|
%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3) #=> [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10", nil, nil]]
|
@@ -124,6 +153,15 @@ Or install it yourself as:
|
|
124
153
|
%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, false) #=> [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]]
|
125
154
|
```
|
126
155
|
|
156
|
+
####Percentile:####
|
157
|
+
`percentile` returns the percentile value for a given percentage.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
[1, 2, 3, 4].percentile(49) # => 2
|
161
|
+
[1, 2, 3, 4].percentile(50) # => 3
|
162
|
+
[1, 2, 3, 4, 5].percentile(50) # => 3
|
163
|
+
```
|
164
|
+
|
127
165
|
####Probablity:####
|
128
166
|
`probability` generates a hash mapping each unique element in the array to the relative frequency, i.e. the probablity, of it appearence.
|
129
167
|
|
@@ -146,7 +184,7 @@ Or install it yourself as:
|
|
146
184
|
```
|
147
185
|
|
148
186
|
####Split:####
|
149
|
-
`split` divides the array into one or more subarrays based on a delimiting value or the result of an optional block.
|
187
|
+
`split` divides the array into one or more subarrays based on a delimiting value or the result of an optional block.
|
150
188
|
|
151
189
|
```ruby
|
152
190
|
[1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
|
@@ -162,7 +200,7 @@ Or install it yourself as:
|
|
162
200
|
```
|
163
201
|
|
164
202
|
####To:####
|
165
|
-
`to` returns the beginning of the array up to position.
|
203
|
+
`to` returns the beginning of the array up to position.
|
166
204
|
|
167
205
|
```ruby
|
168
206
|
["1", "2", "3"].to(0) #=> ["1"]
|
@@ -171,7 +209,7 @@ Or install it yourself as:
|
|
171
209
|
```
|
172
210
|
|
173
211
|
####To Sentence:####
|
174
|
-
`to_sentence` converts the array to a comma-separated sentence where the last element is joined by the connector word.
|
212
|
+
`to_sentence` converts the array to a comma-separated sentence where the last element is joined by the connector word.
|
175
213
|
|
176
214
|
**Options:**
|
177
215
|
* words_connector: “, ”
|
@@ -242,7 +280,7 @@ Or install it yourself as:
|
|
242
280
|
```
|
243
281
|
|
244
282
|
####Exclude:####
|
245
|
-
`exclude?` returns true if the collection does not include the object.
|
283
|
+
`exclude?` returns true if the collection does not include the object.
|
246
284
|
|
247
285
|
```ruby
|
248
286
|
[1, 2, 3].exclude?(4) #=> true
|
@@ -282,7 +320,7 @@ Or install it yourself as:
|
|
282
320
|
```
|
283
321
|
|
284
322
|
####Many:####
|
285
|
-
`many?` returns if collection has more than one element while respecting nil and false as an element.
|
323
|
+
`many?` returns if collection has more than one element while respecting nil and false as an element.
|
286
324
|
|
287
325
|
```ruby
|
288
326
|
[].many? #=> false
|
@@ -311,7 +349,7 @@ Or install it yourself as:
|
|
311
349
|
```
|
312
350
|
|
313
351
|
####Mean:####
|
314
|
-
`mean` returns the average of a collection of numbers.
|
352
|
+
`mean` and `average` returns the average of a collection of numbers.
|
315
353
|
|
316
354
|
```ruby
|
317
355
|
[].mean #=> 0
|
@@ -377,7 +415,7 @@ Or install it yourself as:
|
|
377
415
|
```
|
378
416
|
|
379
417
|
####Sum:####
|
380
|
-
`sum` returns the sum of a collection of numbers.
|
418
|
+
`sum` returns the sum of a collection of numbers.
|
381
419
|
|
382
420
|
```ruby
|
383
421
|
[].sum #=> 0
|
@@ -416,7 +454,7 @@ Or install it yourself as:
|
|
416
454
|
## Hash
|
417
455
|
|
418
456
|
####Assert Valid Keys:####
|
419
|
-
`assert_valid_keys` raises an error if key is not included in a list of keys.
|
457
|
+
`assert_valid_keys` raises an error if key is not included in a list of keys.
|
420
458
|
|
421
459
|
```ruby
|
422
460
|
{}.assert_valid_keys(:foo) #=> {}
|
@@ -425,7 +463,7 @@ Or install it yourself as:
|
|
425
463
|
```
|
426
464
|
|
427
465
|
####Compact:####
|
428
|
-
`compact` and `compact!` returns a hash with non nil values.
|
466
|
+
`compact` and `compact!` returns a hash with non nil values.
|
429
467
|
|
430
468
|
```ruby
|
431
469
|
{}.compact #=> {}
|
@@ -434,7 +472,7 @@ Or install it yourself as:
|
|
434
472
|
```
|
435
473
|
|
436
474
|
####Deep Merge:####
|
437
|
-
`deep_merge` and `deep_merge!` returns a new hash with self and other_hash merged recursively.
|
475
|
+
`deep_merge` and `deep_merge!` returns a new hash with self and other_hash merged recursively.
|
438
476
|
|
439
477
|
```ruby
|
440
478
|
h1 = { a: true, b: { c: [1, 2, 3] } }
|
@@ -443,6 +481,16 @@ h2 = { a: false, b: { x: [3, 4, 5] } }
|
|
443
481
|
h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
444
482
|
```
|
445
483
|
|
484
|
+
####Dig:####
|
485
|
+
`dig` returns the value of a nested hash.
|
486
|
+
|
487
|
+
```ruby
|
488
|
+
h1 = { a: { b: { c: :d } } }
|
489
|
+
|
490
|
+
h1.dig(:a, :b) #=> { c: :d }
|
491
|
+
h1.dig(:a, :b, :c) #=> :d
|
492
|
+
```
|
493
|
+
|
446
494
|
####Except:####
|
447
495
|
`except` and `except!` returns a hash that includes everything but the given keys.
|
448
496
|
|
@@ -484,7 +532,7 @@ h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
|
484
532
|
```
|
485
533
|
|
486
534
|
####Reverse Merge:####
|
487
|
-
`reverse_merge` and `reverse_merge!` merges one hash into other hash.
|
535
|
+
`reverse_merge` and `reverse_merge!` merges one hash into other hash.
|
488
536
|
|
489
537
|
```ruby
|
490
538
|
{}.reverse_merge!(foo: "bar") #=> { foo: "bar" }
|
@@ -536,8 +584,8 @@ h.shuffle! #=> { d: 4, b: 2, c: 3, a: 1 }
|
|
536
584
|
```
|
537
585
|
|
538
586
|
####Slice:####
|
539
|
-
`slice` a hash to include only the given keys. Returns a hash containing the given keys.
|
540
|
-
`slice!` replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs.
|
587
|
+
`slice` a hash to include only the given keys. Returns a hash containing the given keys.
|
588
|
+
`slice!` replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs.
|
541
589
|
|
542
590
|
```ruby
|
543
591
|
h = { a: 1, b: 2, c: 3, d: 4 }
|
@@ -547,7 +595,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
547
595
|
```
|
548
596
|
|
549
597
|
####Stringify Keys:####
|
550
|
-
`stringify_keys` and `stringify_keys!` converts the hash keys to strings.
|
598
|
+
`stringify_keys` and `stringify_keys!` converts the hash keys to strings.
|
551
599
|
|
552
600
|
```ruby
|
553
601
|
{ foo: "foo", "bar" => 'bar' }.stringify_keys #=> { "foo" => "foo", "baz" => "baz" }
|
@@ -563,7 +611,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
563
611
|
```
|
564
612
|
|
565
613
|
####Symbolize Keys:####
|
566
|
-
`symbolize_keys` and `symbolize_keys!` converts the hash keys to symbols.
|
614
|
+
`symbolize_keys` and `symbolize_keys!` converts the hash keys to symbols.
|
567
615
|
|
568
616
|
```ruby
|
569
617
|
{ foo: "foo", "bar" => "bar" }.symbolize_keys #=> { foo: "foo", baz: "baz" }
|
@@ -577,14 +625,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
577
625
|
```
|
578
626
|
|
579
627
|
####Transform Keys:####
|
580
|
-
`transform_keys` and `transform_keys!` a new hash with all keys converted using the block operation.
|
628
|
+
`transform_keys` and `transform_keys!` a new hash with all keys converted using the block operation.
|
581
629
|
|
582
630
|
```ruby
|
583
631
|
{ foo: "bar", baz: "boo" }.transform_keys { |k| k.to_s.upcase } #=> { "FOO" => "bar", "BAZ" => "boo" }
|
584
632
|
```
|
585
633
|
|
586
634
|
####Transform Values:####
|
587
|
-
`transform_values` and `transform_values!` a new hash with all values converted using the block operation.
|
635
|
+
`transform_values` and `transform_values!` a new hash with all values converted using the block operation.
|
588
636
|
|
589
637
|
```ruby
|
590
638
|
{ foo: "bar", baz: "boo" }.transform_values { |v| v.to_s.upcase } #=> {foo: "BAR", baz: "BOO" }
|
@@ -657,6 +705,15 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
657
705
|
3.centuries_in_seconds #=> 9467280000.0
|
658
706
|
```
|
659
707
|
|
708
|
+
####Clamp:####
|
709
|
+
`clamp` returns a comparable between a lower and upper bound.
|
710
|
+
|
711
|
+
```ruby
|
712
|
+
1.clamp(3, 6) # => 3
|
713
|
+
5.clamp(3..6) # => 5
|
714
|
+
8.clamp(3, 6) # => 6
|
715
|
+
```
|
716
|
+
|
660
717
|
####Days in Seconds:####
|
661
718
|
`day_in_seconds` and `days_in_seconds` returns the amount of seconds in n days.
|
662
719
|
|
@@ -698,6 +755,13 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
698
755
|
3.decimeters_in_meters #=> 0.3
|
699
756
|
```
|
700
757
|
|
758
|
+
####degrees_to_radians:####
|
759
|
+
`degrees_to_radians` returns number of degrees into radians.
|
760
|
+
|
761
|
+
```ruby
|
762
|
+
90.degrees_to_radians #=> 1.5707963267948966
|
763
|
+
```
|
764
|
+
|
701
765
|
####Distance:####
|
702
766
|
`distance` returns the absolute difference between numbers.
|
703
767
|
|
@@ -898,7 +962,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
898
962
|
```
|
899
963
|
|
900
964
|
####Multiple Of:####
|
901
|
-
`multiple_of?` returns true if a number can be evenly divided by n.
|
965
|
+
`multiple_of?` returns true if a number can be evenly divided by n.
|
902
966
|
|
903
967
|
```ruby
|
904
968
|
9.multiple_of?(3) #=> true
|
@@ -921,7 +985,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
921
985
|
```
|
922
986
|
|
923
987
|
####Ordinal:####
|
924
|
-
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
988
|
+
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
925
989
|
|
926
990
|
```ruby
|
927
991
|
"1".ordinal #=> "th"
|
@@ -931,7 +995,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
931
995
|
```
|
932
996
|
|
933
997
|
####Ordinalize:####
|
934
|
-
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
998
|
+
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
935
999
|
|
936
1000
|
```ruby
|
937
1001
|
"1".ordinalize #=> "1th"
|
@@ -1175,7 +1239,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1175
1239
|
```
|
1176
1240
|
|
1177
1241
|
####Blank:####
|
1178
|
-
`blank?` determines if an object is empty or nil.
|
1242
|
+
`blank?` determines if an object is empty or nil.
|
1179
1243
|
|
1180
1244
|
```ruby
|
1181
1245
|
"".blank? #=> true
|
@@ -1260,7 +1324,7 @@ true.falsey? #=> false
|
|
1260
1324
|
```
|
1261
1325
|
|
1262
1326
|
####Present:####
|
1263
|
-
`present?` determines if an object is not empty or nil.
|
1327
|
+
`present?` determines if an object is not empty or nil.
|
1264
1328
|
|
1265
1329
|
```ruby
|
1266
1330
|
"Awesome Sting".present? #=> true
|
@@ -1318,7 +1382,7 @@ false.truthy? #=> false
|
|
1318
1382
|
```
|
1319
1383
|
|
1320
1384
|
####Try:####
|
1321
|
-
`try` and `try!` invokes the public method whose name goes as first argument just like public_send does, except that if the receiver does not respond to it the call returns nil rather than raising an exception.
|
1385
|
+
`try` and `try!` invokes the public method whose name goes as first argument just like public_send does, except that if the receiver does not respond to it the call returns nil rather than raising an exception.
|
1322
1386
|
|
1323
1387
|
```ruby
|
1324
1388
|
"example".try(:upcase) #=> "EXAMPLE"
|
@@ -1335,7 +1399,7 @@ false.truthy? #=> false
|
|
1335
1399
|
```
|
1336
1400
|
|
1337
1401
|
####Include With Range:####
|
1338
|
-
`include_with_range?` determines if a range includes another range.
|
1402
|
+
`include_with_range?` determines if a range includes another range.
|
1339
1403
|
|
1340
1404
|
```ruby
|
1341
1405
|
(1..5).include?(1..5) # => true
|
@@ -1344,7 +1408,7 @@ false.truthy? #=> false
|
|
1344
1408
|
```
|
1345
1409
|
|
1346
1410
|
####Overlaps:####
|
1347
|
-
`overlaps?` determines if two ranges overlap each other.
|
1411
|
+
`overlaps?` determines if two ranges overlap each other.
|
1348
1412
|
|
1349
1413
|
```ruby
|
1350
1414
|
(1..5).overlaps?(4..6) # => true
|
@@ -1386,7 +1450,7 @@ false.truthy? #=> false
|
|
1386
1450
|
```
|
1387
1451
|
|
1388
1452
|
####At:####
|
1389
|
-
`at` returns the characters at index position, matching string, or regex.
|
1453
|
+
`at` returns the characters at index position, matching string, or regex.
|
1390
1454
|
|
1391
1455
|
```ruby
|
1392
1456
|
"example_string".at(0) #=> "e"
|
@@ -1398,7 +1462,7 @@ false.truthy? #=> false
|
|
1398
1462
|
```
|
1399
1463
|
|
1400
1464
|
####Camelize:####
|
1401
|
-
`camelize` and `camelize!` transfroms a string to camelcase.
|
1465
|
+
`camelize` and `camelize!` transfroms a string to camelcase.
|
1402
1466
|
|
1403
1467
|
```ruby
|
1404
1468
|
"example_string".camelize #=> "ExampleString"
|
@@ -1408,7 +1472,7 @@ false.truthy? #=> false
|
|
1408
1472
|
```
|
1409
1473
|
|
1410
1474
|
####Classify:####
|
1411
|
-
`classify` and `classify!` creates a class name from a string like Rails does for table names to models.
|
1475
|
+
`classify` and `classify!` creates a class name from a string like Rails does for table names to models.
|
1412
1476
|
|
1413
1477
|
```ruby
|
1414
1478
|
"example_string".classify #=> "ExampleString"
|
@@ -1417,21 +1481,21 @@ false.truthy? #=> false
|
|
1417
1481
|
```
|
1418
1482
|
|
1419
1483
|
####Constantize:####
|
1420
|
-
`constantize` converts a string in an object.
|
1484
|
+
`constantize` converts a string in an object.
|
1421
1485
|
|
1422
1486
|
```ruby
|
1423
1487
|
"Example::String".constantize #=> Class Object
|
1424
1488
|
```
|
1425
1489
|
|
1426
1490
|
####Dasherize:####
|
1427
|
-
`dasherize` and `dasherize!` replaces underscores with dashes in the string.
|
1491
|
+
`dasherize` and `dasherize!` replaces underscores with dashes in the string.
|
1428
1492
|
|
1429
1493
|
```ruby
|
1430
1494
|
"example_string".dasherize #=> "example-string"
|
1431
1495
|
```
|
1432
1496
|
|
1433
1497
|
####Deconstantize:####
|
1434
|
-
`deconstantize` and `deconstantize!` removes the rightmost segment from the constant expression in the string.
|
1498
|
+
`deconstantize` and `deconstantize!` removes the rightmost segment from the constant expression in the string.
|
1435
1499
|
|
1436
1500
|
```ruby
|
1437
1501
|
"Example::String".deconstantize # => "Example"
|
@@ -1442,7 +1506,7 @@ false.truthy? #=> false
|
|
1442
1506
|
```
|
1443
1507
|
|
1444
1508
|
####Demodulize:####
|
1445
|
-
`demodulize` and `demodulize!` removes the module part from the expression in the string.
|
1509
|
+
`demodulize` and `demodulize!` removes the module part from the expression in the string.
|
1446
1510
|
|
1447
1511
|
```ruby
|
1448
1512
|
"Example::String".demodulize #=> "String"
|
@@ -1481,7 +1545,7 @@ false.truthy? #=> false
|
|
1481
1545
|
```
|
1482
1546
|
|
1483
1547
|
####Exclude:####
|
1484
|
-
`exclude?` returns true if the string does not include the other string.
|
1548
|
+
`exclude?` returns true if the string does not include the other string.
|
1485
1549
|
|
1486
1550
|
```ruby
|
1487
1551
|
"example_string".exclude?("exa") #=> false
|
@@ -1489,7 +1553,7 @@ false.truthy? #=> false
|
|
1489
1553
|
```
|
1490
1554
|
|
1491
1555
|
####First:####
|
1492
|
-
`first` returns the first character. If a limit is supplied, returns a substring from the beginning of the string until it reaches the limit value. If the given limit is greater than or equal to the string length, returns a copy of self.
|
1556
|
+
`first` returns the first character. If a limit is supplied, returns a substring from the beginning of the string until it reaches the limit value. If the given limit is greater than or equal to the string length, returns a copy of self.
|
1493
1557
|
|
1494
1558
|
```ruby
|
1495
1559
|
"example".first #=> "e"
|
@@ -1497,8 +1561,17 @@ false.truthy? #=> false
|
|
1497
1561
|
"example".first(3) #=> "exa"
|
1498
1562
|
```
|
1499
1563
|
|
1564
|
+
####Format:####
|
1565
|
+
`format` returns an interpolated string that allows for options.
|
1566
|
+
|
1567
|
+
```ruby
|
1568
|
+
"example %s".format("string") #=> "example string"
|
1569
|
+
"test %{one} %{two}".format(one: "example", two: "string") #=> "test example string"
|
1570
|
+
"%d + %d".format([1, 2]) #=> "1 + 2"
|
1571
|
+
```
|
1572
|
+
|
1500
1573
|
####From:####
|
1501
|
-
`from` returns a substring from the given position to the end of the string. If the position is negative, it is counted from the end of the string.
|
1574
|
+
`from` returns a substring from the given position to the end of the string. If the position is negative, it is counted from the end of the string.
|
1502
1575
|
|
1503
1576
|
```ruby
|
1504
1577
|
"example".from(0) #=> "example"
|
@@ -1506,7 +1579,7 @@ false.truthy? #=> false
|
|
1506
1579
|
```
|
1507
1580
|
|
1508
1581
|
####Humanize:####
|
1509
|
-
`humanize` and `humanize!` transforms a string to a human readable string.
|
1582
|
+
`humanize` and `humanize!` transforms a string to a human readable string.
|
1510
1583
|
|
1511
1584
|
**Options**
|
1512
1585
|
* capitalize: true
|
@@ -1518,7 +1591,7 @@ false.truthy? #=> false
|
|
1518
1591
|
```
|
1519
1592
|
|
1520
1593
|
####Indent:####
|
1521
|
-
`indent` and `indent!` indents the lines in the receiver.
|
1594
|
+
`indent` and `indent!` indents the lines in the receiver.
|
1522
1595
|
|
1523
1596
|
```ruby
|
1524
1597
|
"example".indent(2) #=> " example"
|
@@ -1544,7 +1617,7 @@ false.truthy? #=> false
|
|
1544
1617
|
```
|
1545
1618
|
|
1546
1619
|
####Last:####
|
1547
|
-
`last` returns the last character of the string. If a limit is supplied, returns a substring from the end of the string until it reaches the limit value (counting backwards). If the given limit is greater than or equal to the string length, returns a copy of self.
|
1620
|
+
`last` returns the last character of the string. If a limit is supplied, returns a substring from the end of the string until it reaches the limit value (counting backwards). If the given limit is greater than or equal to the string length, returns a copy of self.
|
1548
1621
|
|
1549
1622
|
```ruby
|
1550
1623
|
"example".last #=> "e"
|
@@ -1562,7 +1635,7 @@ false.truthy? #=> false
|
|
1562
1635
|
```
|
1563
1636
|
|
1564
1637
|
####Ordinal:####
|
1565
|
-
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1638
|
+
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1566
1639
|
|
1567
1640
|
```ruby
|
1568
1641
|
"1".ordinal #=> "th"
|
@@ -1572,7 +1645,7 @@ false.truthy? #=> false
|
|
1572
1645
|
```
|
1573
1646
|
|
1574
1647
|
####Ordinalize:####
|
1575
|
-
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1648
|
+
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1576
1649
|
|
1577
1650
|
```ruby
|
1578
1651
|
"1".ordinalize #=> "1th"
|
@@ -1582,7 +1655,7 @@ false.truthy? #=> false
|
|
1582
1655
|
```
|
1583
1656
|
|
1584
1657
|
####Parameterize:####
|
1585
|
-
`parameterize` and `parameterize!` makes string suitable for a dashed url parameter string.
|
1658
|
+
`parameterize` and `parameterize!` makes string suitable for a dashed url parameter string.
|
1586
1659
|
|
1587
1660
|
```ruby
|
1588
1661
|
"example_string".parameterize #=> "example-string"
|
@@ -1681,7 +1754,7 @@ false.truthy? #=> false
|
|
1681
1754
|
```
|
1682
1755
|
|
1683
1756
|
####Squish:####
|
1684
|
-
`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.
|
1757
|
+
`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.
|
1685
1758
|
|
1686
1759
|
```ruby
|
1687
1760
|
"example string".squish #=> "example string"
|
@@ -1690,7 +1763,7 @@ false.truthy? #=> false
|
|
1690
1763
|
```
|
1691
1764
|
|
1692
1765
|
####Titleize:####
|
1693
|
-
`titleize` and `titleize!` capitalizes each word in a string.
|
1766
|
+
`titleize` and `titleize!` capitalizes each word in a string.
|
1694
1767
|
|
1695
1768
|
```ruby
|
1696
1769
|
"example string".titleize #=> "Example String"
|
@@ -1699,7 +1772,7 @@ false.truthy? #=> false
|
|
1699
1772
|
```
|
1700
1773
|
|
1701
1774
|
####To:####
|
1702
|
-
`to` returns a substring from the beginning of the string to the given position. If the position is negative, it is counted from the end of the string.
|
1775
|
+
`to` returns a substring from the beginning of the string to the given position. If the position is negative, it is counted from the end of the string.
|
1703
1776
|
|
1704
1777
|
```ruby
|
1705
1778
|
"example".to(0) #=> "example"
|
@@ -1708,7 +1781,7 @@ false.truthy? #=> false
|
|
1708
1781
|
```
|
1709
1782
|
|
1710
1783
|
####Truncate:####
|
1711
|
-
`truncate` a given text after a given length if text is longer than length.
|
1784
|
+
`truncate` a given text after a given length if text is longer than length.
|
1712
1785
|
|
1713
1786
|
**Options**
|
1714
1787
|
* omission: "..."
|
@@ -1723,7 +1796,7 @@ false.truthy? #=> false
|
|
1723
1796
|
```
|
1724
1797
|
|
1725
1798
|
####Truncate Words:####
|
1726
|
-
`truncate_words` truncates a given text after a given number of words.
|
1799
|
+
`truncate_words` truncates a given text after a given number of words.
|
1727
1800
|
|
1728
1801
|
**Options**
|
1729
1802
|
* omission: "..."
|
@@ -1736,7 +1809,7 @@ false.truthy? #=> false
|
|
1736
1809
|
```
|
1737
1810
|
|
1738
1811
|
####Underscore:####
|
1739
|
-
`underscore` and `underscore!` transforms a string to snakecase.
|
1812
|
+
`underscore` and `underscore!` transforms a string to snakecase.
|
1740
1813
|
|
1741
1814
|
```ruby
|
1742
1815
|
"ExampleString".underscore #=> "example_string"
|
@@ -1887,7 +1960,7 @@ Time.now.stamp(:datetime) #=> "January 09, 2014 02:31 pm"
|
|
1887
1960
|
|
1888
1961
|
## Contributing
|
1889
1962
|
|
1890
|
-
1. Fork it ( http://github.com
|
1963
|
+
1. Fork it ( http://github.com/drexed/active_object/fork )
|
1891
1964
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
1892
1965
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
1893
1966
|
4. Push to the branch (`git push origin my-new-feature`)
|