fizx-parsley-ruby 0.3.1 → 0.3.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.
- data/lib/parsley.rb +17 -1
- data/parsley-ruby.gemspec +1 -1
- data/test/test_parsley.rb +15 -1
- metadata +1 -1
data/lib/parsley.rb
CHANGED
@@ -16,7 +16,7 @@ class Parsley
|
|
16
16
|
|
17
17
|
def initialize(parsley, incl = "")
|
18
18
|
if(parsley.is_a?(Hash))
|
19
|
-
parsley = parsley.to_json
|
19
|
+
parsley = recursive_stringify(parsley).to_json
|
20
20
|
end
|
21
21
|
@@mutex ||= Mutex.new
|
22
22
|
@@mutex.synchronize do
|
@@ -63,4 +63,20 @@ class Parsley
|
|
63
63
|
|
64
64
|
@parsley.parse(options)
|
65
65
|
end
|
66
|
+
private
|
67
|
+
|
68
|
+
def recursive_stringify(obj)
|
69
|
+
case obj
|
70
|
+
when Hash
|
71
|
+
obj.inject({}) do |memo, (k, v)|
|
72
|
+
memo[k.to_s] = recursive_stringify(v)
|
73
|
+
memo
|
74
|
+
end
|
75
|
+
when Array
|
76
|
+
obj.map{|e| recursive_stringify(e) }
|
77
|
+
else
|
78
|
+
obj.to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
66
82
|
end
|
data/parsley-ruby.gemspec
CHANGED
data/test/test_parsley.rb
CHANGED
@@ -14,6 +14,20 @@ class TestParsley < Test::Unit::TestCase
|
|
14
14
|
assert_equal "/c/sf/shopping", out["categories"][0]["href"]
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_parsley_should_raise_if_value_syntax_error
|
18
|
+
assert_raises(ParsleyError) do
|
19
|
+
Parsley.new({"foo" => nil})
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_raises(ParsleyError) do
|
23
|
+
Parsley.new({"foo" => ""})
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_raises(ParsleyError) do
|
27
|
+
Parsley.new({"foo" => "<<<<<<<<<<<"})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
17
31
|
def test_yelp_xml
|
18
32
|
@parsley = Parsley.new(File.read(@let))
|
19
33
|
out = @parsley.parse(:file => @home, :output => :xml)
|
@@ -38,7 +52,7 @@ class TestParsley < Test::Unit::TestCase
|
|
38
52
|
|
39
53
|
def test_xml
|
40
54
|
@parsley = Parsley.new("hi" => "h1")
|
41
|
-
xml = "<?xml version=\"1.0\"?>\n<parsley:root xmlns:parsley=\"http://parselets.com/json\"><hi position=\"
|
55
|
+
xml = "<?xml version=\"1.0\"?>\n<parsley:root xmlns:parsley=\"http://parselets.com/json\"><hi position=\"105\">Nick's Crispy Tacos</hi></parsley:root>\n"
|
42
56
|
assert_equal(xml, @parsley.parse(:file => @page, :output => :xml))
|
43
57
|
end
|
44
58
|
|