Skip to content

Commit

Permalink
Merge pull request #78 from Fryguy/update_docs
Browse files Browse the repository at this point in the history
Updated documentation and changelog
  • Loading branch information
bdunne authored Jan 31, 2020
2 parents 2de9327 + 1c8aa6e commit 6bb1224
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.0.0] - 2020-01-31
### Changed
- **BREAKING**: Moved Object#descendant_get to Class#descendant_get [[#75](https://github.com/ManageIQ/more_core_extensions/pull/75)]
- **BREAKING**: Removed deprecated Enumerable#stable_sort_by [[#76](https://github.com/ManageIQ/more_core_extensions/pull/76)]

## [3.8.0] - 2020-01-31
### Changed
- Renamed Enumerable#stable_sort_by to Array#tabular_sort [[#68](https://github.com/ManageIQ/more_core_extensions/pull/68)]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS

#### Array

* core_ext/array/compact_map.rb
* `#compact_map` - Collect non-nil results from the block
* core_ext/array/deletes.rb
* `#delete_blanks` - Deletes all items where the value is blank
* `#delete_nils` - Deletes all items where the value is nil
Expand All @@ -35,6 +37,8 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
* core_ext/array/random.rb
* `#random_index` - Picks a valid index randomly
* `#random_element` - Picks an element randomly
* core_ext/array/sorting.rb
* `#tabular_sort` - Sorts an Array of Hashes by specific columns
* core_ext/array/stretch.rb
* `.stretch` - Stretch all argument Arrays to make them the same size
* `.stretch!` - Stretch all argument Arrays to make them the same size. Modifies the arguments in place.
Expand Down
22 changes: 22 additions & 0 deletions lib/more_core_extensions/core_ext/array/sorting.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
module MoreCoreExtensions
module StableSorting
# Sorts an Array of Hashes by specific columns.
#
# Rows are sorted by +col_names+, if given, otherwise by the given block.
# The +order+ parameter can be given :ascending or :descending and
# defaults to :ascending.
#
# Note:
# - Strings are sorted case-insensitively
# - nil values are sorted last
# - Boolean values are sorted alphabetically (i.e. false then true)
#
# [
# {:col1 => 'b', :col2 => 2},
# {:col1 => 'b', :col2 => 1},
# {:col1 => 'A', :col2 => 1}
# ].tabular_sort([:col1, :col2])
#
# # => [
# # {:col1 => 'A', :col2 => 1},
# # {:col1 => 'b', :col2 => 1},
# # {:col1 => 'b', :col2 => 2}
# # ]
def tabular_sort(col_names = nil, order = nil, &block)
# stabilizer is needed because of
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170565
Expand Down

0 comments on commit 6bb1224

Please sign in to comment.