active_object 2.2.5 → 2.3.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/README.md +54 -2
- data/lib/active_object.rb +11 -11
- data/lib/active_object/array.rb +4 -3
- data/lib/active_object/date.rb +88 -88
- data/lib/active_object/enumerable.rb +19 -10
- data/lib/active_object/hash.rb +11 -12
- data/lib/active_object/integer.rb +17 -19
- data/lib/active_object/numeric.rb +64 -36
- data/lib/active_object/object.rb +3 -3
- data/lib/active_object/string.rb +65 -57
- data/lib/active_object/time.rb +136 -136
- data/lib/active_object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2328a0445ce30462a324b76b837c44b0a1acc3b8
|
|
4
|
+
data.tar.gz: 0829cad78f360aa10b7138f4f33b04cbd3ace852
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59a21514f21c8b8be2a495c6651bdf95669e176bd386065124e08b3b51defa1960094f4882352c9d7cffb52c76a942c1982d61fe57d757687950469775a5fc82
|
|
7
|
+
data.tar.gz: b651f4a4d3a201f348afce2aa6609a2689b7807260eeda22a110865efe161092a134f705935cf1fcb0b84658380d06caed818f42b7b9795cfcac801b22a47b19
|
data/README.md
CHANGED
|
@@ -734,6 +734,24 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
|
734
734
|
3.grams_in_grams #=> 3
|
|
735
735
|
```
|
|
736
736
|
|
|
737
|
+
####Greater Than:####
|
|
738
|
+
`greater_than?` returns true if self is greater than n.
|
|
739
|
+
|
|
740
|
+
```ruby
|
|
741
|
+
3.greater_than?(2) #=> true
|
|
742
|
+
3.greater_than?(3) #=> false
|
|
743
|
+
3.greater_than?(4) #=> false
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
####Greater Than or Equal To:####
|
|
747
|
+
`greater_than_or_equal_to?` returns true if self is greater than or equal to n.
|
|
748
|
+
|
|
749
|
+
```ruby
|
|
750
|
+
3.greater_than_or_equal_to?(2) #=> true
|
|
751
|
+
3.greater_than_or_equal_to?(3) #=> true
|
|
752
|
+
3.greater_than_or_equal_to?(4) #=> false
|
|
753
|
+
```
|
|
754
|
+
|
|
737
755
|
####Hectograms in Grams:####
|
|
738
756
|
`hectogram_in_grams` and `hectograms_in_grams` returns the amount of grams in n hectograms.
|
|
739
757
|
|
|
@@ -762,6 +780,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
|
762
780
|
3.inches_in_inches #=> 3
|
|
763
781
|
```
|
|
764
782
|
|
|
783
|
+
####Inside:####
|
|
784
|
+
`inside?` returns true if n is greater than start and less than finish. Similar to between but does not return true if equal to self.
|
|
785
|
+
|
|
786
|
+
```ruby
|
|
787
|
+
3.inside?(1, 5) #=> true
|
|
788
|
+
3.inside?(3, 5) #=> false
|
|
789
|
+
```
|
|
790
|
+
|
|
765
791
|
####Kilobytes in Bytes:####
|
|
766
792
|
`kilobyte_in_bytes` and `kilobytes_in_bytes` returns the amount of bytes in n kilobytes.
|
|
767
793
|
|
|
@@ -783,6 +809,24 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
|
783
809
|
3.kilometers_in_meters #=> 3000
|
|
784
810
|
```
|
|
785
811
|
|
|
812
|
+
####Less Than:####
|
|
813
|
+
`less_than?` returns true if self is less than n.
|
|
814
|
+
|
|
815
|
+
```ruby
|
|
816
|
+
3.less_than?(2) #=> false
|
|
817
|
+
3.less_than?(3) #=> false
|
|
818
|
+
3.less_than?(4) #=> true
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
####Less Than or Equal To:####
|
|
822
|
+
`less_than_or_equal_to?` returns true if self is less than or equal to n.
|
|
823
|
+
|
|
824
|
+
```ruby
|
|
825
|
+
3.less_than_or_equal_to?(2) #=> false
|
|
826
|
+
3.less_than_or_equal_to?(3) #=> true
|
|
827
|
+
3.less_than_or_equal_to?(4) #=> true
|
|
828
|
+
```
|
|
829
|
+
|
|
786
830
|
####Metric Ton in Ounces:####
|
|
787
831
|
`metric_ton_in_ounces` and `metric_tons_in_ounces` returns the amount of grams in n metric_tons.
|
|
788
832
|
|
|
@@ -896,6 +940,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
|
896
940
|
3.ounces_in_ounces #=> 48
|
|
897
941
|
```
|
|
898
942
|
|
|
943
|
+
####Outside:####
|
|
944
|
+
`outside?` returns true if n is less than start or greater than finish.
|
|
945
|
+
|
|
946
|
+
```ruby
|
|
947
|
+
3.outside?(4, 5) #=> true
|
|
948
|
+
3.outside?(3, 5) #=> false
|
|
949
|
+
```
|
|
950
|
+
|
|
899
951
|
####Pad:####
|
|
900
952
|
`pad` returns a string reprensentation of the number padded with pad_num to a specified length.
|
|
901
953
|
|
|
@@ -1513,7 +1565,7 @@ false.truthy? #=> false
|
|
|
1513
1565
|
```
|
|
1514
1566
|
|
|
1515
1567
|
####Pollute:####
|
|
1516
|
-
`pollute` pollutes the space between every letter in a string, so it will be exempt from any impending string searches.
|
|
1568
|
+
`pollute` and `pollute!` pollutes the space between every letter in a string, so it will be exempt from any impending string searches.
|
|
1517
1569
|
|
|
1518
1570
|
```ruby
|
|
1519
1571
|
"test".pollute #=> "t^--^--^e^--^--^s^--^--^t^--^--^"
|
|
@@ -1635,7 +1687,7 @@ false.truthy? #=> false
|
|
|
1635
1687
|
```
|
|
1636
1688
|
|
|
1637
1689
|
####Unpollute:####
|
|
1638
|
-
`unpollute` removes the default or custom pollution character. Can also be used to remove an unwanted character.
|
|
1690
|
+
`unpollute` and `unpollute!` removes the default or custom pollution character. Can also be used to remove an unwanted character.
|
|
1639
1691
|
|
|
1640
1692
|
```ruby
|
|
1641
1693
|
"t^--^--^e^--^--^s^--^--^t^--^--^".unpollute #=> "test"
|
data/lib/active_object.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
1
|
+
require "active_object/version"
|
|
2
|
+
require "active_object/array"
|
|
3
|
+
require "active_object/date"
|
|
4
|
+
require "active_object/enumerable"
|
|
5
|
+
require "active_object/hash"
|
|
6
|
+
require "active_object/integer"
|
|
7
|
+
require "active_object/numeric"
|
|
8
|
+
require "active_object/object"
|
|
9
|
+
require "active_object/range"
|
|
10
|
+
require "active_object/string"
|
|
11
|
+
require "active_object/time"
|
data/lib/active_object/array.rb
CHANGED
|
@@ -49,6 +49,7 @@ class Array
|
|
|
49
49
|
|
|
50
50
|
def groups(number)
|
|
51
51
|
return([]) if number <= 0
|
|
52
|
+
|
|
52
53
|
n, r = size.divmod(number)
|
|
53
54
|
collection = (0..(n - 1)).collect { |i| self[(i * number), number] }
|
|
54
55
|
r > 0 ? collection << self[-r, r] : collection
|
|
@@ -154,9 +155,9 @@ class Array
|
|
|
154
155
|
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector)
|
|
155
156
|
|
|
156
157
|
default_connectors = {
|
|
157
|
-
words_connector: ', ',
|
|
158
|
-
two_words_connector: ' and ',
|
|
159
|
-
last_word_connector: ', and '
|
|
158
|
+
words_connector: ', '.freeze,
|
|
159
|
+
two_words_connector: ' and '.freeze,
|
|
160
|
+
last_word_connector: ', and '.freeze
|
|
160
161
|
}
|
|
161
162
|
options = default_connectors.merge!(options)
|
|
162
163
|
|
data/lib/active_object/date.rb
CHANGED
|
@@ -5,99 +5,99 @@ class Date
|
|
|
5
5
|
formatters = string.scan /[a-z0-9_]+/i
|
|
6
6
|
|
|
7
7
|
format_units = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
8
|
+
'd' => 'd',
|
|
9
|
+
'day' => 'd',
|
|
10
|
+
'day_padded' => 'd',
|
|
11
|
+
'dd' => '-d',
|
|
12
|
+
'Day' => '-d',
|
|
13
|
+
'day_unpadded' => '-d',
|
|
14
|
+
'ddd' => '_d',
|
|
15
|
+
'DAY' => '_d',
|
|
16
|
+
'day_blank' => '_d',
|
|
17
|
+
'dddd' => 'j',
|
|
18
|
+
'day_of_the_year' => 'j',
|
|
19
|
+
'm' => 'm',
|
|
20
|
+
'month' => 'm',
|
|
21
|
+
'month_padded' => 'm',
|
|
22
|
+
'mm' => '-m',
|
|
23
|
+
'Month' => '-m',
|
|
24
|
+
'month_unpadded' => '-m',
|
|
25
|
+
'mmm' => '_m',
|
|
26
|
+
'MONTH' => '_m',
|
|
27
|
+
'month_blank' => '_m',
|
|
28
|
+
'mmmm' => 'B',
|
|
29
|
+
'month_name' => 'B',
|
|
30
|
+
'mmmmm' => 'b',
|
|
31
|
+
'month_name_abbr' => 'b',
|
|
32
|
+
'w' => 'u',
|
|
33
|
+
'weekday' => 'u',
|
|
34
|
+
'ww' => 'w',
|
|
35
|
+
'weekday_offset' => 'w',
|
|
36
|
+
'www' => 'A',
|
|
37
|
+
'weekday_name' => 'A',
|
|
38
|
+
'wwww' => 'a',
|
|
39
|
+
'weekday_name_abbr' => 'a',
|
|
40
|
+
'wwwww' => 'W',
|
|
41
|
+
'week' => 'W',
|
|
42
|
+
'wwwwww' => 'U',
|
|
43
|
+
'week_offset' => 'U',
|
|
44
|
+
'yy' => 'y',
|
|
45
|
+
'yr' => 'y',
|
|
46
|
+
'yyyy' => 'Y',
|
|
47
|
+
'year' => 'Y',
|
|
48
|
+
'ampm' => 'P',
|
|
49
|
+
'meridian' => 'P',
|
|
50
|
+
'AMPM' => 'p',
|
|
51
|
+
'MERIDIAN' => 'p'
|
|
52
|
+
}.freeze
|
|
53
53
|
|
|
54
|
-
strftime(formatters.map { |f| "%#{format_units.fetch(f)}#{delimiters.shift || ''}" }.join
|
|
54
|
+
strftime(formatters.map { |f| "%#{format_units.fetch(f)}#{delimiters.shift || ''}" }.join)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
def to_format(key)
|
|
57
|
+
def to_format(key=:datetime_iso)
|
|
58
58
|
format_units = {
|
|
59
|
-
month:
|
|
60
|
-
month_padded:
|
|
61
|
-
month_unpadded:
|
|
62
|
-
month_blank:
|
|
63
|
-
month_name:
|
|
64
|
-
month_name_abbr:
|
|
65
|
-
weekday:
|
|
66
|
-
weekday_padded:
|
|
67
|
-
weekday_unpadded:
|
|
68
|
-
weekday_blank:
|
|
69
|
-
weekday_name:
|
|
70
|
-
weekday_name_abbr:
|
|
71
|
-
yr:
|
|
72
|
-
year_abbr:
|
|
73
|
-
year:
|
|
74
|
-
date:
|
|
75
|
-
date_abbr:
|
|
76
|
-
date_iso:
|
|
77
|
-
datetime:
|
|
78
|
-
datetime_abbr:
|
|
79
|
-
datetime_iso:
|
|
80
|
-
datetime_imperical:
|
|
81
|
-
datetime_imperical_abbr:
|
|
82
|
-
datetime_imperical_iso:
|
|
83
|
-
datetime_tzn:
|
|
84
|
-
datetime_abbr_tzn:
|
|
85
|
-
datetime_iso_tzn:
|
|
86
|
-
datetime_imperical_tzn:
|
|
87
|
-
datetime_imperical_abbr_tzn:
|
|
88
|
-
datetime_imperical_iso_tzn:
|
|
89
|
-
day:
|
|
90
|
-
day_abbr:
|
|
91
|
-
day_iso:
|
|
92
|
-
daytime:
|
|
93
|
-
daytime_abbr:
|
|
94
|
-
daytime_iso:
|
|
95
|
-
daytime_imperical:
|
|
96
|
-
daytime_imperical_abbr:
|
|
97
|
-
daytime_imperical_iso:
|
|
98
|
-
}
|
|
59
|
+
month: '%m',
|
|
60
|
+
month_padded: '%m',
|
|
61
|
+
month_unpadded: '%-m',
|
|
62
|
+
month_blank: '%_m',
|
|
63
|
+
month_name: '%B',
|
|
64
|
+
month_name_abbr: '%b',
|
|
65
|
+
weekday: '%d',
|
|
66
|
+
weekday_padded: '%d',
|
|
67
|
+
weekday_unpadded: '%-d',
|
|
68
|
+
weekday_blank: '%_d',
|
|
69
|
+
weekday_name: '%A',
|
|
70
|
+
weekday_name_abbr: '%a',
|
|
71
|
+
yr: '%y',
|
|
72
|
+
year_abbr: '%y',
|
|
73
|
+
year: '%Y',
|
|
74
|
+
date: '%B %-d, %Y',
|
|
75
|
+
date_abbr: '%b %-d, %Y',
|
|
76
|
+
date_iso: '%Y-%m-%d',
|
|
77
|
+
datetime: '%B %-d, %Y %H:%M',
|
|
78
|
+
datetime_abbr: '%b %-d, %Y %H:%M',
|
|
79
|
+
datetime_iso: '%Y-%m-%d %H:%M',
|
|
80
|
+
datetime_imperical: '%B %-d, %Y %I:%M %P',
|
|
81
|
+
datetime_imperical_abbr: '%b %-d, %Y %I:%M %P',
|
|
82
|
+
datetime_imperical_iso: '%Y-%m-%d %I:%M %P',
|
|
83
|
+
datetime_tzn: '%B %-d, %Y %H:%M %Z',
|
|
84
|
+
datetime_abbr_tzn: '%b %-d, %Y %H:%M %Z',
|
|
85
|
+
datetime_iso_tzn: '%Y-%m-%d %H:%M %z',
|
|
86
|
+
datetime_imperical_tzn: '%B %-d, %Y %I:%M %P %Z',
|
|
87
|
+
datetime_imperical_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
|
|
88
|
+
datetime_imperical_iso_tzn: '%Y-%m-%d %I:%M %P %z',
|
|
89
|
+
day: '%B %-d',
|
|
90
|
+
day_abbr: '%b %-d',
|
|
91
|
+
day_iso: '%m-%d',
|
|
92
|
+
daytime: '%B %-d %H:%M',
|
|
93
|
+
daytime_abbr: '%b %-d %H:%M',
|
|
94
|
+
daytime_iso: '%m-%d %H:%M',
|
|
95
|
+
daytime_imperical: '%B %-d %I:%M %P',
|
|
96
|
+
daytime_imperical_abbr: '%b %-d %I:%M %P',
|
|
97
|
+
daytime_imperical_iso: '%m-%d %I:%M %P'
|
|
98
|
+
}.freeze
|
|
99
99
|
|
|
100
|
-
strftime(format_units.fetch(key))
|
|
100
|
+
strftime(format_units.fetch(key.to_sym))
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
alias_method :stamp, :to_format
|
|
@@ -18,7 +18,7 @@ module Enumerable
|
|
|
18
18
|
if block_given?
|
|
19
19
|
map(&block).difference(identity)
|
|
20
20
|
else
|
|
21
|
-
inject { |d,v| d - v } || identity
|
|
21
|
+
inject { |d, v| d - v } || identity
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -26,13 +26,15 @@ module Enumerable
|
|
|
26
26
|
if block_given?
|
|
27
27
|
map(&block).divisible(identity)
|
|
28
28
|
else
|
|
29
|
-
inject { |d,v| d / v } || identity
|
|
29
|
+
inject { |d, v| d / v } || identity
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def drop_last(n)
|
|
34
34
|
collection_size = to_a.size
|
|
35
|
+
|
|
35
36
|
return(self) if n > collection_size
|
|
37
|
+
|
|
36
38
|
self[0...(collection_size - n)]
|
|
37
39
|
end
|
|
38
40
|
|
|
@@ -67,7 +69,7 @@ module Enumerable
|
|
|
67
69
|
if block_given?
|
|
68
70
|
map(&block).exponential(identity)
|
|
69
71
|
else
|
|
70
|
-
inject { |d,v| d ** v } || identity
|
|
72
|
+
inject { |d, v| d ** v } || identity
|
|
71
73
|
end
|
|
72
74
|
end
|
|
73
75
|
|
|
@@ -103,12 +105,13 @@ module Enumerable
|
|
|
103
105
|
|
|
104
106
|
def mean(identity=0)
|
|
105
107
|
return(identity) unless size > 0
|
|
108
|
+
|
|
106
109
|
collection_size = size
|
|
107
|
-
sum / collection_size.to_f
|
|
110
|
+
sum.to_f / collection_size.to_f
|
|
108
111
|
end
|
|
109
112
|
|
|
110
113
|
def median(identity=0)
|
|
111
|
-
collection_size = size
|
|
114
|
+
collection_size = size.to_f
|
|
112
115
|
collection_sorted = sort
|
|
113
116
|
|
|
114
117
|
return(identity) unless collection_size > 0
|
|
@@ -123,8 +126,8 @@ module Enumerable
|
|
|
123
126
|
def mode(identity=0)
|
|
124
127
|
return(identity) unless size > 0
|
|
125
128
|
|
|
126
|
-
frequency_distribution = inject(Hash.new(0)) { |h,v| h[v] += 1; h }
|
|
127
|
-
frequency_top_two = frequency_distribution.sort { |k,v| v[1] <=> k[1] }.take(2)
|
|
129
|
+
frequency_distribution = inject(Hash.new(0)) { |h, v| h[v] += 1; h }
|
|
130
|
+
frequency_top_two = frequency_distribution.sort { |k, v| v[1] <=> k[1] }.take(2)
|
|
128
131
|
|
|
129
132
|
if frequency_top_two.size == 1
|
|
130
133
|
frequency_top_two.first.first
|
|
@@ -139,12 +142,13 @@ module Enumerable
|
|
|
139
142
|
if block_given?
|
|
140
143
|
map(&block).multiple(identity)
|
|
141
144
|
else
|
|
142
|
-
inject { |d,v| d * v } || identity
|
|
145
|
+
inject { |d, v| d * v } || identity
|
|
143
146
|
end
|
|
144
147
|
end
|
|
145
148
|
|
|
146
149
|
def range(identity=0)
|
|
147
150
|
return(identity) unless size > 0
|
|
151
|
+
|
|
148
152
|
collection_sorted = sort
|
|
149
153
|
collection_sorted.last - collection_sorted.first
|
|
150
154
|
end
|
|
@@ -157,6 +161,7 @@ module Enumerable
|
|
|
157
161
|
|
|
158
162
|
def standard_deviation(identity=0)
|
|
159
163
|
return(identity) if size < 2
|
|
164
|
+
|
|
160
165
|
Math.sqrt(variance)
|
|
161
166
|
end
|
|
162
167
|
|
|
@@ -165,14 +170,16 @@ module Enumerable
|
|
|
165
170
|
if block_given?
|
|
166
171
|
map(&block).sum(identity)
|
|
167
172
|
else
|
|
168
|
-
inject { |s,v| s + v } || identity
|
|
173
|
+
inject { |s, v| s + v } || identity
|
|
169
174
|
end
|
|
170
175
|
end
|
|
171
176
|
end
|
|
172
177
|
|
|
173
178
|
def take_last(n)
|
|
174
179
|
collection_size = to_a.size
|
|
180
|
+
|
|
175
181
|
return(self) if n > collection_size
|
|
182
|
+
|
|
176
183
|
self[(collection_size - n)..-1]
|
|
177
184
|
end
|
|
178
185
|
|
|
@@ -186,9 +193,11 @@ module Enumerable
|
|
|
186
193
|
|
|
187
194
|
def variance(identity=0)
|
|
188
195
|
collection_size = size
|
|
196
|
+
|
|
189
197
|
return(identity) if collection_size <= 1
|
|
198
|
+
|
|
190
199
|
sum = inject(0.0) { |s,v| s + (v - mean) ** 2.0 }
|
|
191
|
-
sum / (collection_size.to_f - 1.0)
|
|
200
|
+
sum.to_f / (collection_size.to_f - 1.0)
|
|
192
201
|
end
|
|
193
202
|
|
|
194
203
|
end
|