str2hash 0.1.0 → 0.1.1

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.
data/README.md CHANGED
@@ -35,34 +35,26 @@ No nested hashes, no arrays (yet). No bindings, only values.
35
35
 
36
36
  ## Version information
37
37
 
38
+ * 0.1.1 - Bug fix, handle empty strings
38
39
  * 0.1.0 - Gem setup, Documentation
39
- * 0.0.2 - Minor fixes
40
- * 0.0.1 - Initial version
41
-
42
40
 
43
41
  ## License
44
42
 
45
43
  MIT License:
46
44
 
47
- Copyright (c) 2013 karl l, <karl@ninjacontrol.com>
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to
51
- deal in the Software without restriction, including without limitation the
52
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
53
- sell copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in
57
- all copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
64
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
65
- IN THE SOFTWARE.
45
+ Copyright (c) 2013 Karl L (karl@ninjacontrol.com)
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
48
+ "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
56
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
57
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66
58
 
67
59
  ## Author
68
60
 
data/lib/str2hash.rb CHANGED
@@ -35,8 +35,8 @@ class HashParse < Parslet::Parser
35
35
 
36
36
  rule(:string) {
37
37
  (
38
- (str("'") >> match["^'"].repeat(1).as(:str) >> str("'")) |
39
- (str('"') >> match['^"'].repeat(1).as(:str) >> str('"'))
38
+ (str("'") >> match["^'"].repeat.as(:str) >> str("'")) |
39
+ (str('"') >> match['^"'].repeat.as(:str) >> str('"'))
40
40
  ) >> sp?
41
41
  }
42
42
 
@@ -95,7 +95,17 @@ class HashTransform < Parslet::Transform
95
95
 
96
96
  rule(:bin_int => simple(:i)) { Integer(i) }
97
97
 
98
- rule(:str => simple(:s)) { s.to_s }
98
+ rule(:str => subtree(:s)) {
99
+ if s.is_a?(Array)
100
+ if s.eql?([]) # empty string
101
+ ""
102
+ else
103
+ s
104
+ end
105
+ else
106
+ s.to_s
107
+ end
108
+ }
99
109
 
100
110
  rule(:pat => simple(:p)) { /#{p}/ }
101
111
 
@@ -1,4 +1,4 @@
1
1
  module Str2Hash
2
2
  # Version string (uses semanic versioning)
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
@@ -25,7 +25,9 @@ PRODS = [
25
25
  {s: "{ foo: /foo/ }", h: {:foo => /foo/}},
26
26
  {s: "{ foo: true }", h: {:foo => true}},
27
27
  {s: "{ :foo => :bar, :foo2 => :bar2}", h: {:foo => :bar, :foo2 => :bar2}},
28
- {s: ":foo => :bar, :foo2 => :bar2", h: {:foo => :bar, :foo2 => :bar2}}
28
+ {s: ":foo => :bar, :foo2 => :bar2", h: {:foo => :bar, :foo2 => :bar2}},
29
+ {s: "{:foo => ''}", h: {:foo => ''}},
30
+ {s: "{:foo => \"\"}", h: {:foo => ""}}
29
31
  ]
30
32
 
31
33
  describe HashParse do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: str2hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -2288426739317148869
109
+ hash: -22957540454798774
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -2288426739317148869
118
+ hash: -22957540454798774
119
119
  requirements: []
120
120
  rubyforge_project:
121
121
  rubygems_version: 1.8.24