creative_rails_utilities 0.4.2 → 0.4.3

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: 620bfb4a460b454df919b37aab5763681d8d40aa
4
- data.tar.gz: 219d14e7b22adec3b646e0228b1ae9526d27308f
3
+ metadata.gz: 05cb9d231a2ce10ff623f11bfb2c279e509bf1c3
4
+ data.tar.gz: e420b4d185fb32b3567dfd704ba161e7401deae1
5
5
  SHA512:
6
- metadata.gz: f769642de2b237235ccdb934993bbdca02b0932008fc8dc1b2c1a56a5d355d935e11c8c7c8eecbd985b4d3715723427fb7dd058372a1311d349753be18d39a68
7
- data.tar.gz: 734ce1eaed645703c867ac60d4defcec7b43996197dceb3f8da9ae4d9ef80966376513d4a3ac8eae18a90441a928a978c22d2da0f4f30290e54e79d339f9a7fa
6
+ metadata.gz: 25e3bef44073c8256869afff81c3e146460706f3aee318c5241592ae6b04c4300babb77a14bc57be360f031185b356b796134aee370a8f6eb07ab2de3f9ba44a
7
+ data.tar.gz: 9cd6e337b76da4aff9333ac3095b421bd9ea3eca92fee610f485ea2ea7ee385d6f417dc1d2323d1c83d31bdd6efc51a024bd841f487c348eff65856b5167af48
data/CHANGELOG.md CHANGED
@@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
8
8
  -
9
9
  ```
10
10
 
11
+ ## [0.4.3] - 2016-07-13
12
+ ### Added
13
+ - Array#histogram
14
+ - Array#by_popularity
15
+
11
16
  ## [0.4.2] - 2016-06-17
12
17
  ### Added
13
18
  - Object.chain_if
data/README.md CHANGED
@@ -12,6 +12,20 @@ Intended for `Rails >= 4.0.0`, but will probably work for older projects with ro
12
12
 
13
13
  Feel free to read the source under `/lib/creative_rails_utilities/` and peruse the method "it" lines under `/spec`
14
14
 
15
+ ##### Array
16
+
17
+ ```ruby
18
+ # Array#histogram # returns a histogram hash of elements sorted by most value first
19
+ %i|c a b a a b|.histogram
20
+ # => {a: 3, b: 2, c: 1}
21
+ ```
22
+
23
+ ```ruby
24
+ # Array#by_popularity # returns a semi-histogram array of unique elements sorted by most numerous element first
25
+ %i|c a b a a b|.histogram
26
+ # => [:a, :b, :c]}
27
+ ```
28
+
15
29
  ##### Date
16
30
 
17
31
  ```ruby
@@ -0,0 +1,12 @@
1
+ class Array
2
+ def histogram
3
+ histogram = each_with_object(Hash.new(0)) {|n, memo| memo[n] += 1}.sort_by{|k, v| -v}
4
+
5
+ return Hash[histogram]
6
+ end
7
+
8
+ def by_popularity
9
+ return histogram.keys
10
+ end
11
+
12
+ end
@@ -1,3 +1,3 @@
1
1
  module CreativeRailsUtilities
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -4,9 +4,11 @@ require 'active_support/core_ext'
4
4
  require 'hashrush'
5
5
  require 'ruby_dig'
6
6
 
7
- require "creative_rails_utilities/error_helper"
8
- require "creative_rails_utilities/hash"
7
+ require "creative_rails_utilities/error_helper" # higher because require order reasons
8
+
9
+ require "creative_rails_utilities/array"
9
10
  require "creative_rails_utilities/date"
11
+ require "creative_rails_utilities/hash"
10
12
  require "creative_rails_utilities/numeric"
11
13
  require "creative_rails_utilities/object"
12
14
  require "creative_rails_utilities/string"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creative_rails_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Creative
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -171,6 +171,7 @@ files:
171
171
  - bin/setup
172
172
  - creative_rails_utilities.gemspec
173
173
  - lib/creative_rails_utilities.rb
174
+ - lib/creative_rails_utilities/array.rb
174
175
  - lib/creative_rails_utilities/date.rb
175
176
  - lib/creative_rails_utilities/error_helper.rb
176
177
  - lib/creative_rails_utilities/hash.rb