Sha256: 05a8e5cc11e5e972ee3f33ca800d64c9c92781eab1ac38bacac78d3ce81188b9

Contents?: true

Size: 455 Bytes

Versions: 74

Compression:

Stored size: 455 Bytes

Contents

class SliceableHash
 
  def initialize(hash)
    @hash = hash
  end

  # Return a hash that includes only the given keys.
  def slice(*keys)
    keys.map! { |key| @hash.convert_key(key) } if @hash.respond_to?(:convert_key, true)
    keys.each_with_object(@hash.class.new) { |k, hash| hash[k] = @hash[k] if @hash.has_key?(k) && if_string_not_empty(@hash[k]) }
  end
  
  def if_string_not_empty(val)
    val.kind_of?(String) ? !val.empty? : true
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
intercom-3.5.10 lib/ext/sliceable_hash.rb
intercom-3.5.9 lib/ext/sliceable_hash.rb
intercom-3.5.8 lib/ext/sliceable_hash.rb
intercom-3.5.7 lib/ext/sliceable_hash.rb
intercom-3.5.6 lib/ext/sliceable_hash.rb
intercom-3.5.5 lib/ext/sliceable_hash.rb
intercom-3.5.4 lib/ext/sliceable_hash.rb
intercom-3.5.3 lib/ext/sliceable_hash.rb
intercom-3.5.2 lib/ext/sliceable_hash.rb
cogniteev-intercom-2.5.4 lib/ext/sliceable_hash.rb
intercom-3.5.1 lib/ext/sliceable_hash.rb
intercom-3.4.0 lib/ext/sliceable_hash.rb
intercom-3.3.0 lib/ext/sliceable_hash.rb
intercom-3.2.0 lib/ext/sliceable_hash.rb
intercom-3.1.0 lib/ext/sliceable_hash.rb
intercom-3.0.6 lib/ext/sliceable_hash.rb
intercom-3.0.5 lib/ext/sliceable_hash.rb
intercom-3.0.4 lib/ext/sliceable_hash.rb
intercom-3.0.3 lib/ext/sliceable_hash.rb
intercom-3.0.2 lib/ext/sliceable_hash.rb