Skip to content

Latest commit

 

History

History
173 lines (136 loc) · 7.49 KB

README.md

File metadata and controls

173 lines (136 loc) · 7.49 KB

MoreCoreExtensions

MoreCoreExtensions are a set of core extensions beyond those provided by ActiveSupport.

Gem Version CI Code Climate Coverage Status

Join the chat at https://gitter.im/ManageIQ/more_core_extensions

Extensions Provided

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
    • #deep_delete - Deletes nested hash key elements
  • core_ext/array/duplicates.rb
    • #duplicates - Returns an Array of the duplicates found
  • core_ext/array/element_counts.rb
    • #element_counts - Returns a Hash of each element to the count of those elements
  • core_ext/array/inclusions.rb
    • #include_all? - Returns whether the Array contains all of the items
    • #include_any? - Returns whether the Array contains any of the items
    • #include_none? - Returns whether the Array contains none of the items
    • #includes_index? - Returns whether the Array has a value at the index
  • core_ext/array/math.rb
    • #mean - Returns the mean of an Array of Numerics
    • #stddev - Returns the standard deviation of an Array of Numerics
    • #variance - Returns the variance of an Array of Numerics
  • core_ext/array/nested.rb (see Shared)
    • #delete_blank_paths - Deletes all paths where the value is blank
  • 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.
    • #stretch - Stretch receiver to be the same size as the longest argument Array.
    • #stretch! - Stretch receiver to be the same size as the longest argument Array. Modifies the receiver in place.
    • #zip_stretched - Zip arguments stretching the receiver if necessary
  • core_ext/array/tableize.rb
    • #tableize - Create a string representation of receiver in a tabular format if receiver is an Array of Arrays or an Array of Hashes

Class

  • core_ext/class/hierarchy.rb
    • #descendant_get - Returns the descendant with a given name
    • #hierarchy - Returns a tree-like Hash structure of all descendants.
    • #lineage - Returns an Array of all superclasses.
    • #leaf_subclasses - Returns an Array of all descendants which have no subclasses.

Hash

  • core_ext/hash/deletes.rb
    • #delete_blanks - Deletes all keys where the value is blank
    • #delete_nils - Deletes all keys where the value is nil
    • #deep_delete - Deletes nested hash key elements
  • core_ext/hash/nested.rb (see Shared)
    • #delete_blank_paths - Deletes all paths where the value is blank
  • core_ext/hash/sorting.rb (see Shared)
    • #sort! - Replace the original with the sorted hash
    • #sort_by! - Replace the original with the sorted_by hash

Module

  • core_ext/module/cache_with_timeout.rb
    • #cache_with_timeout - Creates singleton methods that cache the results of the given block, but only for a short amount of time.
    • .clear_all_cache_with_timeout - Globally clears all cached values across all classes.
  • core_ext/module/namespace.rb
    • #namespace - Returns an Array with the namespace to the current Module

Numeric

  • core_ext/numeric/clamp.rb
    • #clamp - Clamp a number to a minimum and/or maximum value
  • core_ext/numeric/math.rb
    • #square - Returns the square of a Numeric
  • core_ext/numeric/rounding.rb
    • #round_down - Round down to the specified precision
    • #round_up - Round up to the specified precision

Object

  • core_ext/module/deep_send.rb
    • #deep_send - Invokes the specified methods continuously, unless encountering a nil value.
  • core_ext/module/namespace.rb
    • #in_namespace? - Returns whether or not the object is in the given namespace

Process

  • core_ext/process/pause_resume.rb
    • .pause - Pauses a process
    • .resume - Resumes a paused process
    • .alive? - Returns whether or not a process is running

Range

  • core_ext/range/step_value.rb
    • #step_value - Step through a range at a given increment

String

  • core_ext/string/decimal_suffix.rb
    • #decimal_si_to_big_decimal - Returns a BigDecimal based on the number and suffix given
    • #decimal_si_to_f - Returns a Float based on the number and suffix given
  • core_ext/string/formats.rb
    • #email? - Returns whether or not the String is an= valid email
    • #domain_name? - Returns whether or not the String is a valid domain name
    • #hostname? - Returns whether or not the String is a valid hostname
    • #ipv4? - Returns whether or not the String is an IPv4 address
    • #ipv6? - Returns whether or not the String is an IPv6 address
    • #ipaddress? - Returns whether or not the String is an IPv4 or IPv6 address
    • #integer? - Returns whether or not the String is an integer
    • #guid? - Returns whether or not the String is a valid GUID
  • core_ext/string/hex_dump.rb
    • #hex_dump - Dumps the string in a hex editor style format
  • core_ext/string/iec60027_2.rb
    • #iec_60027_2_to_i - Convert strings with an IEC60027-2 suffix to an integer
  • core_ext/string/to_i_with_method.rb
    • #to_f_with_method - Converts to a Float while also evaluating a method invocation
    • #to_i_with_method - Converts to an Integer while also evaluating a method invocation
    • #number_with_method? - Determines if the object contains a number with a method invocation

Symbol

  • core_ext/symbol/to_i.rb
    • #to_i - Returns the integer value of a symbol

Shared

  • core_ext/shared/nested.rb
    • #deep_clone - Performs a Marshal based deep clone
    • #delete_path - Delete the value at the specified nesting
    • #fetch_path - Fetch the value at the specified nesting
    • #find_path - Detect which nesting holds the specified value
    • #has_key_path? - Check if a key exists at the specified nesting
    • #include_path? - alias of #has_key_path?
    • #key_path? - alias of #has_key_path?
    • #member_path? - alias of #has_key_path?
    • #store_path - Store a value at the specified nesting

Installation

Add this line to your application's Gemfile:

gem 'more_core_extensions'

And then execute:

$ bundle

Or install it yourself as:

$ gem install more_core_extensions

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.