fizx-parsley-ruby 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "parsley-ruby"
3
- s.version = "0.3.1"
3
+ s.version = "0.3.2"
4
4
  s.date = "2009-03-23"
5
5
  s.summary = "Ruby binding for parsley"
6
6
  s.email = "kyle@kylemaxwell.com"
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=\"63\">Nick's Crispy Tacos</hi></parsley:root>\n"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fizx-parsley-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Maxwell