hash_kit 0.5.4 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0705b38ac887a45532cacae4d2f83b8a3c60541e
4
- data.tar.gz: 9b169ab5202f456d33056ecbd632c2d34b8df7a5
2
+ SHA256:
3
+ metadata.gz: d485bd2d33cd889018f3f33be7b6f63c4b39950435c85d653a7e5bf83e5c7178
4
+ data.tar.gz: 338476fcf2204466db3d9bf84bfe378c182dbcf3d36331051cce3365c5f12db0
5
5
  SHA512:
6
- metadata.gz: 472b2a1274bb14570d19b2e01e49ba7ee10b9e10242489aabcd911520d23bd9165a3075743bb25fa981bcc447db04d8aecbcb240020ac499514dd8b06197b6dd
7
- data.tar.gz: 612c25732193b2a387808ed8637cf82b1dc72aa675337ad073fa45db9b2656d775432d5bc02d93de487c41fafc35c842a62aa1cc8cc08936480c9f2b259abcc3
6
+ metadata.gz: dd0d6f1890ff8578a3e46bc9da603efa1a1ca269da23163cbbb5f0b62b45543cd6cc7c34cb275f745a78f01a87b7d6976d24ac3c0767dd8a05b3066d04b05bff
7
+ data.tar.gz: 4e9328fbfdbe271c9f437a6cbfcee49ca795d68bcc926b719ac8a4ac4be25e73f5693e30a635f3f141171889e7c7e1b1f6ead5bb8573b66e20650f86bc4c26f8
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HashKit
4
+ # Hash kit Helper class
2
5
  class Helper
3
-
4
- #This method is called to make a hash allow indifferent access (it will accept both strings & symbols for a valid key).
6
+ # This method is called to make a hash allow indifferent access (it will
7
+ # accept both strings & symbols for a valid key).
5
8
  def indifferent!(hash)
6
- unless hash.is_a?(Hash)
7
- return
8
- end
9
+ return unless hash.is_a?(Hash)
9
10
 
10
- #set the default proc to allow the key to be either string or symbol if a matching key is found.
11
+ # Set the default proc to allow the key to be either string or symbol if
12
+ # a matching key is found.
11
13
  hash.default_proc = proc do |h, k|
12
14
  if h.key?(k.to_s)
13
15
  h[k.to_s]
@@ -18,9 +20,9 @@ module HashKit
18
20
  end
19
21
  end
20
22
 
21
- #recursively process any child hashes
23
+ # Recursively process any child hashes
22
24
  hash.each do |key,value|
23
- if hash[key] != nil
25
+ unless hash[key].nil?
24
26
  if hash[key].is_a?(Hash)
25
27
  indifferent!(hash[key])
26
28
  elsif hash[key].is_a?(Array)
@@ -33,9 +35,7 @@ module HashKit
33
35
  end
34
36
 
35
37
  def indifferent_array!(array)
36
- unless array.is_a?(Array)
37
- return
38
- end
38
+ return unless array.is_a?(Array)
39
39
 
40
40
  array.each do |i|
41
41
  if i.is_a?(Hash)
@@ -46,14 +46,16 @@ module HashKit
46
46
  end
47
47
  end
48
48
 
49
- #This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application.
49
+ # This method is called to convert all the keys of a hash into symbols to
50
+ # allow consistent usage of hashes within your Ruby application.
50
51
  def symbolize(hash)
51
52
  {}.tap do |h|
52
53
  hash.each { |key, value| h[key.to_sym] = map_value_symbol(value) }
53
54
  end
54
55
  end
55
56
 
56
- #This method is called to convert all the keys of a hash into strings to allow consistent usage of hashes within your Ruby application.
57
+ # This method is called to convert all the keys of a hash into strings to
58
+ # allow consistent usage of hashes within your Ruby application.
57
59
  def stringify(hash)
58
60
  {}.tap do |h|
59
61
  hash.each { |key, value| h[key.to_s] = map_value_string(value) }
@@ -73,18 +75,22 @@ module HashKit
73
75
  hash
74
76
  end
75
77
 
76
- def from_hash(hash, klass, transforms = [])
78
+ # Return an object of type klass from the values in the given hash
79
+ #
80
+ # @param [Hash] hash
81
+ # @param [Class] klass
82
+ # @param [Array] transforms
83
+ # @return [Object]
84
+ def from_hash(hash, klass, transforms = [])
77
85
  obj = klass.new
78
- if hash ==nil || hash == {}
79
- return obj
80
- end
86
+ return obj if hash.nil? || hash.empty?
87
+ raise ArgumentError, "#{hash.inspect} is not a hash" unless hash.is_a?(Hash)
88
+
89
+ hash.each do |k, v|
90
+ next unless obj.respond_to?(k)
81
91
 
82
- hash.each do |k,v|
83
- if !obj.respond_to?(k)
84
- next
85
- end
86
92
  transform = transforms.detect { |t| t.key.to_sym == k.to_sym }
87
- if transform != nil
93
+ if !transform.nil?
88
94
  if v.is_a?(Hash)
89
95
  child = from_hash(v, transform.klass, transforms)
90
96
  obj.instance_variable_set("@#{k}", child)
@@ -98,7 +104,8 @@ module HashKit
98
104
  obj.instance_variable_set("@#{k}", v)
99
105
  end
100
106
  end
101
- return obj
107
+
108
+ obj
102
109
  end
103
110
 
104
111
  private
@@ -123,7 +130,7 @@ module HashKit
123
130
 
124
131
  def standard_type?(obj)
125
132
  [
126
- String, Fixnum, Numeric, Float, Date, DateTime, Time, Integer, TrueClass, FalseClass, NilClass, Symbol
133
+ String, Numeric, Float, Date, DateTime, Time, Integer, TrueClass, FalseClass, NilClass, Symbol
127
134
  ].detect do |klass|
128
135
  obj.is_a?(klass)
129
136
  end
@@ -0,0 +1,5 @@
1
+ # Namespace
2
+ module HashKit
3
+ # :nodoc:
4
+ VERSION = '0.7.0'
5
+ end
metadata CHANGED
@@ -1,59 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage One
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.21'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.21'
69
83
  description: Toolkit for working with Hashes
70
84
  email:
71
85
  - vaughan.britton@sage.com
@@ -78,6 +92,7 @@ files:
78
92
  - lib/hash_kit.rb
79
93
  - lib/hash_kit/helper.rb
80
94
  - lib/hash_kit/transform_item.rb
95
+ - lib/hash_kit/version.rb
81
96
  homepage: https://github.com/sage/hash_kit
82
97
  licenses:
83
98
  - MIT
@@ -97,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
112
  - !ruby/object:Gem::Version
98
113
  version: '0'
99
114
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.4.5
115
+ rubygems_version: 3.3.5
102
116
  signing_key:
103
117
  specification_version: 4
104
118
  summary: Toolkit for working with Hashes