hash_tools 1.1.2 → 1.2.2
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 +4 -4
- data/hash_tools.gemspec +3 -3
- data/lib/hash_tools.rb +1 -1
- data/lib/hash_tools/indifferent.rb +10 -0
- data/spec/hash_tools/indifferent_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ab5e9066d46815ff0a1a2a97b9a1f382773673b
|
|
4
|
+
data.tar.gz: b9f930223045e67b684639e2b44b659f91ebe1db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
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-
|
|
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
|
@@ -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.
|
|
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
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|