hash_tools 1.1.2 → 1.2.2

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: f54f9fd6710aaef28b13b13637b86bdd9f0ea7da
4
- data.tar.gz: db6c828e930c6d65f73ecade6369c0f5f7dc7e6a
3
+ metadata.gz: 4ab5e9066d46815ff0a1a2a97b9a1f382773673b
4
+ data.tar.gz: b9f930223045e67b684639e2b44b659f91ebe1db
5
5
  SHA512:
6
- metadata.gz: ee6c201fc0de4f0bc85eb458d9ba76e1c1aa3b0e06b4d4e52703edda33fc48ff75cf1620192cdb8f6c175c43d36983f6878a9d917470cf0c27f5d3f27a052d5f
7
- data.tar.gz: 2582099ceb80dd540f8b5bb04b086ef576960eb221a5a251f4830008ed458ea373fbe918c97fb30bef0246eaae86d84027fcaed3f7e7d46d985b6f73bd9023cf
6
+ metadata.gz: b62b54f10e976670dad3fb77d671e62005a3990504a5d1de6b4c75a7aac7822fbd897032d463a77a1adaec41abb5d438a78436dc2e14a8367e7cfd9fccebf904
7
+ data.tar.gz: 379f8dfc139e506d4ddc00a6543e2b618d358adcced40796a67ae9985bdceb62d9239bd3ce2719a4aefdb3f3d0419738df792216311fc40749ba8be6d1b0e15b
data/hash_tools.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: hash_tools 1.1.2 ruby lib
5
+ # stub: hash_tools 1.2.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "hash_tools"
9
- s.version = "1.1.2"
9
+ s.version = "1.2.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Julik Tarkhanov"]
14
- s.date = "2015-11-20"
14
+ s.date = "2015-12-06"
15
15
  s.description = "Do useful things to Ruby Hashes"
16
16
  s.email = "me@julik.nl"
17
17
  s.extra_rdoc_files = [
data/lib/hash_tools.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module HashTools
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.2'
3
3
 
4
4
  require_relative 'hash_tools/indifferent'
5
5
 
@@ -57,6 +57,16 @@ class HashTools::Indifferent < SimpleDelegator
57
57
  __getobj__.has_key?( __transform_key__(k))
58
58
  end
59
59
 
60
+ # Checks if the value at the given key is non-empty
61
+ #
62
+ # @param k[String,Symbol] the key to check
63
+ def value_present?(k)
64
+ return false unless key?(k)
65
+ v = self[k]
66
+ return false unless v
67
+ return !v.to_s.empty?
68
+ end
69
+
60
70
  # Yields each key - value pair of the indifferent.
61
71
  # If the value is a Hash as well, that hash will be wrapped in an Indifferent before returning
62
72
  def each(&blk)
@@ -56,6 +56,20 @@ describe HashTools::Indifferent do
56
56
  expect(wrapper.keys).to eq(h_deep.keys)
57
57
  end
58
58
 
59
+ it 'supports has_non_empty?' do
60
+ h_deep = {:a => 1, :b => '', :c => false, :d => nil}
61
+ wrapper = described_class.new(h_deep)
62
+
63
+ expect(wrapper).to be_value_present(:a)
64
+
65
+ expect(wrapper).not_to be_value_present(:z)
66
+ expect(wrapper).not_to be_value_present('z')
67
+
68
+ expect(wrapper).not_to be_value_present(:b)
69
+ expect(wrapper).not_to be_value_present(:c)
70
+ expect(wrapper).not_to be_value_present(:d)
71
+ end
72
+
59
73
  it 'supports map' do
60
74
  h_deep = {:a => {:b => 1}, 'b' => {'b' => 2}}
61
75
  wrapper = described_class.new(h_deep)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec