nested_hash 0.1.1 → 0.1.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.
@@ -1,4 +1,11 @@
1
1
 
2
+ 2012-05-23 Guillermo Alvarez Fernandez <guillermo@cientifico.net>
3
+
4
+ * nested_hash.rb (sanitize_long_key): Added the ability of sanitize the
5
+ single key, or the initial key of the hash.
6
+
7
+ * nested_hash.rb (process_nested): Now the index of the array are respected.
8
+
2
9
  2012-05-16 Guillermo Alvarez Fernandez <guillermo@cientifico.net>
3
10
 
4
11
  * nested_hash.rb (process): Now the values are sanitized correctly
data/lib/nested_hash.rb CHANGED
@@ -4,7 +4,7 @@ class NestedHash < Hash
4
4
 
5
5
  def initialize(hash = {})
6
6
  hash.each do |key,v|
7
- key = sanitize_key(key)
7
+ key = sanitize_long_key(key)
8
8
 
9
9
  if is_valid_key?(key)
10
10
  process(key,v)
@@ -32,6 +32,10 @@ class NestedHash < Hash
32
32
  true
33
33
  end
34
34
 
35
+ def sanitize_long_key(key)
36
+ key
37
+ end
38
+
35
39
  def sanitize_key(key)
36
40
  key
37
41
  end
@@ -59,12 +63,13 @@ class NestedHash < Hash
59
63
 
60
64
  def process_nested(key, value)
61
65
  keys = key.split(".")
62
- previous = keys.shift
66
+ previous = sanitize_key(keys.shift)
63
67
  top = keys.inject(self) do |memo,key|
64
68
  if is_for_array?(key)
65
69
  memo[previous] ||= []
66
70
  key = key.to_i
67
71
  else
72
+ key = sanitize_key(key)
68
73
  memo[previous] ||= {}
69
74
  end
70
75
  a = memo[previous]
@@ -72,11 +77,7 @@ class NestedHash < Hash
72
77
  a
73
78
  end
74
79
 
75
- if top.is_a?(Array)
76
- top << value
77
- else
78
- top[previous] = value
79
- end
80
+ top[previous] = value
80
81
  rescue => e
81
82
  handle_exception(e, key, value)
82
83
  end
@@ -1,3 +1,3 @@
1
1
  class NestedHash < Hash
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,26 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nested_hash
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
6
11
  platform: ruby
7
- authors:
8
- - Guillermo Álvarez
12
+ authors:
13
+ - "Guillermo A\xCC\x81lvarez"
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-05-16 00:00:00.000000000Z
17
+
18
+ date: 2012-05-23 00:00:00 +00:00
19
+ default_executable:
13
20
  dependencies: []
14
- description: ! 'For example a hash like { "properties.age" => 3 } will be converted
15
- into { "properties" => {"age" => 3}} '
16
- email:
21
+
22
+ description: "For example a hash like { \"properties.age\" => 3 } will be converted into { \"properties\" => {\"age\" => 3}} "
23
+ email:
17
24
  - guillermo@cientifico.net
18
25
  executables: []
26
+
19
27
  extensions: []
28
+
20
29
  extra_rdoc_files: []
21
- files:
30
+
31
+ files:
22
32
  - .gitignore
23
- - CHANGELOG
33
+ - Changelog
24
34
  - Gemfile
25
35
  - README.md
26
36
  - Rakefile
@@ -28,29 +38,39 @@ files:
28
38
  - lib/nested_hash/version.rb
29
39
  - nested_hash.gemspec
30
40
  - test/test_simple_to_complex_hash.rb
31
- homepage: ''
41
+ has_rdoc: true
42
+ homepage: ""
32
43
  licenses: []
44
+
33
45
  post_install_message:
34
46
  rdoc_options: []
35
- require_paths:
47
+
48
+ require_paths:
36
49
  - lib
37
- required_ruby_version: !ruby/object:Gem::Requirement
50
+ required_ruby_version: !ruby/object:Gem::Requirement
38
51
  none: false
39
- requirements:
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
60
  none: false
45
- requirements:
46
- - - ! '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
49
68
  requirements: []
69
+
50
70
  rubyforge_project: nested_hash
51
- rubygems_version: 1.8.16
71
+ rubygems_version: 1.6.2
52
72
  signing_key:
53
73
  specification_version: 3
54
74
  summary: Convert a simple one level hash to a multilevel hash
55
- test_files:
56
- - test/test_simple_to_complex_hash.rb
75
+ test_files: []
76
+