active_object 4.0.11 → 4.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed9947a6dbf1f2b8107341630ab8390765a5252c
4
- data.tar.gz: 7bebb1fc8c9883503e662a735d3b255c538db7af
3
+ metadata.gz: 3732d8cc57873bb65509cb15667b89fcbee98f9f
4
+ data.tar.gz: ab738019896ac8a100889863367536c73c12fe7c
5
5
  SHA512:
6
- metadata.gz: b27667689796c171a245bc77802eb83cb3c50aefe1cdf3c4ea26097c0605852833a0d2b23e4e1380ade5c9fc9a54b7c8fa6fcf3ea02afdbb37592fef1c46b5e8
7
- data.tar.gz: 37db9622ae481b0d518f4758a83feb1608ef911536e211326effdfad9d301815cdd63d9d28eff5a702856260f108f9d20f6a1e6ba2a1f3a02ae8ada425d9ae1b
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` | %V | (00..53) |
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) |
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActiveObject
2
- VERSION = '4.0.11'.freeze
2
+ VERSION = '4.0.12'.freeze
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: 4.0.11
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-06-07 00:00:00.000000000 Z
11
+ date: 2017-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable