active_object 4.0.11 → 4.0.12
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 +28 -10
- data/lib/active_object/array.rb +0 -11
- data/lib/active_object/enumerable.rb +16 -0
- data/lib/active_object/numeric.rb +8 -0
- 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: 3732d8cc57873bb65509cb15667b89fcbee98f9f
|
4
|
+
data.tar.gz: ab738019896ac8a100889863367536c73c12fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88f3622cc418dee000c18b1a57509feee48ae4fdea33dbc04e9a6f04a654ab24f0ec82e0c5dd295018971bce7ec6bd27e1e0b5d5993da60deab06cdf122adad
|
7
|
+
data.tar.gz: 5f794f16ad17d9bb8a54d1fb618f00570f90d5d60a0e32ede62a6bb42a00c07eb9c868516f4fef75f66aff4091aeec2d844c5b5ead8fc55bf9c754440cc61a11
|
data/README.md
CHANGED
@@ -166,15 +166,6 @@ end
|
|
166
166
|
['', 3, 4].nillify! #=> [nil, 3, 4]
|
167
167
|
```
|
168
168
|
|
169
|
-
**Percentile:**
|
170
|
-
`percentile` returns the percentile value for a given percentage.
|
171
|
-
|
172
|
-
```ruby
|
173
|
-
[1, 2, 3, 4].percentile(49) # => 2
|
174
|
-
[1, 2, 3, 4].percentile(50) # => 3
|
175
|
-
[1, 2, 3, 4, 5].percentile(50) # => 3
|
176
|
-
```
|
177
|
-
|
178
169
|
**Probablity:**
|
179
170
|
`probability` generates a hash mapping each unique element in the array to the relative frequency, i.e. the probablity, of it appearence.
|
180
171
|
|
@@ -381,6 +372,16 @@ end
|
|
381
372
|
[1,2,3].multiple #=> 6
|
382
373
|
```
|
383
374
|
|
375
|
+
**Percentile:**
|
376
|
+
`percentile` returns the percentile value for a given percentage.
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
[].percentile(50) # => 2
|
380
|
+
[].percentile(50, nil) # => 3
|
381
|
+
[1, 2, 3, 4].percentile(50) # => 2.5
|
382
|
+
[1, 2, 3, 4, 5].percentile(50) # => 3
|
383
|
+
```
|
384
|
+
|
384
385
|
**Range:**
|
385
386
|
`range` returns the difference between the smallest and largest value of a collection of numbers.
|
386
387
|
|
@@ -810,6 +811,23 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
810
811
|
3.feet_in_inches #=> 36
|
811
812
|
```
|
812
813
|
|
814
|
+
**Fractional:**
|
815
|
+
`fractional` returns the numbers after '.' of a float.
|
816
|
+
|
817
|
+
```ruby
|
818
|
+
1.0.fraction #=> 0.0
|
819
|
+
12.2456.fraction #=> 0.2456
|
820
|
+
-12.2456.fraction #=> 0.2456
|
821
|
+
```
|
822
|
+
|
823
|
+
**Fraction?:**
|
824
|
+
`fraction?` returns if its a fractional.
|
825
|
+
|
826
|
+
```ruby
|
827
|
+
1.0.fraction? #=> false
|
828
|
+
12.2456.fraction? #=> true
|
829
|
+
```
|
830
|
+
|
813
831
|
**Gigabytes in Bytes:**
|
814
832
|
`gigabyte_in_bytes` and `gigabytes_in_bytes` returns the amount of bytes in n gigabytes.
|
815
833
|
|
@@ -1951,7 +1969,7 @@ Time.now.stamp(:datetime) #=> 'January 09, 2014 02:31 pm'
|
|
1951
1969
|
| Month - name abbreviated | `:month_name_abbr_year` | %a | Jan 2015 |
|
1952
1970
|
| Week - iso | `:week_iso` | %V | (00..53) |
|
1953
1971
|
| Week - week year iso | `:week_year_iso` | %V-%G | 04-2014 |
|
1954
|
-
| Week - sunday week | `:sunday_week` | %
|
1972
|
+
| Week - sunday week | `:sunday_week` | %U | (00..53) |
|
1955
1973
|
| Week - monday week | `:monday_week` | %V | (00..53) |
|
1956
1974
|
| Weekday - digits zero-padded | `:weekday_padded` | %A | (01..31) |
|
1957
1975
|
| Weekday - digits unpadded | `:weekday_unpadded` | %a | (1..31) |
|
data/lib/active_object/array.rb
CHANGED
@@ -116,17 +116,6 @@ module ActiveObject::Array
|
|
116
116
|
replace(nillify)
|
117
117
|
end
|
118
118
|
|
119
|
-
def percentile(percentage)
|
120
|
-
total_size = size
|
121
|
-
|
122
|
-
if total_size > 1
|
123
|
-
index = (total_size * percentage) / 100.0
|
124
|
-
sort[index]
|
125
|
-
else
|
126
|
-
first
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
119
|
def probability
|
131
120
|
hash = Hash.new(0.0)
|
132
121
|
differ = 0.0
|
@@ -138,6 +138,22 @@ module Enumerable
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
+
def percentile(num, identity = 0)
|
142
|
+
return identity unless length.positive?
|
143
|
+
|
144
|
+
collection_sorted = sort
|
145
|
+
rank = (num.to_f / 100) * (length + 1)
|
146
|
+
|
147
|
+
if rank.fraction?
|
148
|
+
sample_0 = collection_sorted[rank.truncate - 1]
|
149
|
+
sample_1 = collection_sorted[rank.truncate]
|
150
|
+
|
151
|
+
(rank.fraction * (sample_1 - sample_0)) + sample_0
|
152
|
+
else
|
153
|
+
collection_sorted[rank - 1]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
141
157
|
def range(identity = 0)
|
142
158
|
return identity unless length.positive?
|
143
159
|
|
@@ -163,6 +163,14 @@ module ActiveObject::Numeric
|
|
163
163
|
|
164
164
|
alias_method :foot_in_inches, :feet_in_inches
|
165
165
|
|
166
|
+
def fraction
|
167
|
+
(self - self.truncate).abs
|
168
|
+
end
|
169
|
+
|
170
|
+
def fraction?
|
171
|
+
fraction != 0.0
|
172
|
+
end
|
173
|
+
|
166
174
|
def gigabytes_in_bytes
|
167
175
|
self * GIGABYTE
|
168
176
|
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: 4.0.
|
4
|
+
version: 4.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|