crack 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/crack.gemspec +10 -10
- data/lib/crack.rb +2 -2
- data/lib/crack/xml.rb +0 -2
- data/test/xml_test.rb +11 -18
- metadata +5 -5
data/crack.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.3.
|
7
|
+
s.name = "crack"
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.email =
|
11
|
+
s.authors = ["John Nunemaker", "Wynn Netherland"]
|
12
|
+
s.date = "2013-01-09"
|
13
|
+
s.email = "nunemaker@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
16
16
|
"README.rdoc"
|
@@ -35,11 +35,11 @@ Gem::Specification.new do |s|
|
|
35
35
|
"test/test_helper.rb",
|
36
36
|
"test/xml_test.rb"
|
37
37
|
]
|
38
|
-
s.homepage =
|
39
|
-
s.require_paths = [
|
40
|
-
s.rubyforge_project =
|
41
|
-
s.rubygems_version =
|
42
|
-
s.summary =
|
38
|
+
s.homepage = "http://github.com/jnunemaker/crack"
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubyforge_project = "crack"
|
41
|
+
s.rubygems_version = "1.8.10"
|
42
|
+
s.summary = "Really simple JSON and XML parsing, ripped from Merb and Rails."
|
43
43
|
|
44
44
|
if s.respond_to? :specification_version then
|
45
45
|
s.specification_version = 3
|
data/lib/crack.rb
CHANGED
data/lib/crack/xml.rb
CHANGED
@@ -40,9 +40,7 @@ class REXMLUtilityNode #:nodoc:
|
|
40
40
|
self.typecasts["decimal"] = lambda{|v| v.nil? ? nil : BigDecimal(v.to_s)}
|
41
41
|
self.typecasts["double"] = lambda{|v| v.nil? ? nil : v.to_f}
|
42
42
|
self.typecasts["float"] = lambda{|v| v.nil? ? nil : v.to_f}
|
43
|
-
self.typecasts["symbol"] = lambda{|v| v.nil? ? nil : v.to_sym}
|
44
43
|
self.typecasts["string"] = lambda{|v| v.to_s}
|
45
|
-
self.typecasts["yaml"] = lambda{|v| v.nil? ? nil : YAML.load(v)}
|
46
44
|
self.typecasts["base64Binary"] = lambda{|v| v.unpack('m').first }
|
47
45
|
|
48
46
|
self.available_typecasts = self.typecasts.keys
|
data/test/xml_test.rb
CHANGED
@@ -65,10 +65,10 @@ class XmlTest < Test::Unit::TestCase
|
|
65
65
|
}
|
66
66
|
}
|
67
67
|
}
|
68
|
-
|
68
|
+
|
69
69
|
Crack::XML.parse(xml).should == hash
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
context "Parsing xml with text and attributes" do
|
73
73
|
setup do
|
74
74
|
xml =<<-XML
|
@@ -90,20 +90,20 @@ class XmlTest < Test::Unit::TestCase
|
|
90
90
|
}
|
91
91
|
}
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
should "be parse attributes for text node if present" do
|
95
95
|
@data['opt']['user'][0].attributes.should == {'login' => 'grep'}
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
should "default attributes to empty hash if not present" do
|
99
99
|
@data['opt']['user'][1].attributes.should == {}
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
should "add 'attributes' accessor methods to parsed instances of String" do
|
103
103
|
@data['opt']['user'][0].respond_to?(:attributes).should be(true)
|
104
104
|
@data['opt']['user'][0].respond_to?(:attributes=).should be(true)
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
should "not add 'attributes' accessor methods to all instances of String" do
|
108
108
|
"some-string".respond_to?(:attributes).should be(false)
|
109
109
|
"some-string".respond_to?(:attributes=).should be(false)
|
@@ -149,7 +149,7 @@ class XmlTest < Test::Unit::TestCase
|
|
149
149
|
Crack::XML.parse(xml)['tag'].should =~ Regexp.new(k)
|
150
150
|
end
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
should "should unescape XML entities in attributes" do
|
154
154
|
xml_entities.each do |k,v|
|
155
155
|
xml = "<tag attr='Some content #{v}'></tag>"
|
@@ -226,7 +226,6 @@ class XmlTest < Test::Unit::TestCase
|
|
226
226
|
<approved type="boolean"></approved>
|
227
227
|
<written-on type="date"></written-on>
|
228
228
|
<viewed-at type="datetime"></viewed-at>
|
229
|
-
<content type="yaml"></content>
|
230
229
|
<parent-id></parent-id>
|
231
230
|
</topic>
|
232
231
|
EOT
|
@@ -237,7 +236,6 @@ class XmlTest < Test::Unit::TestCase
|
|
237
236
|
'approved' => nil,
|
238
237
|
'written_on' => nil,
|
239
238
|
'viewed_at' => nil,
|
240
|
-
'content' => nil,
|
241
239
|
'parent_id' => nil
|
242
240
|
}
|
243
241
|
Crack::XML.parse(topic_xml)["topic"].should == expected_topic_hash
|
@@ -254,7 +252,6 @@ class XmlTest < Test::Unit::TestCase
|
|
254
252
|
<replies-close-in type="integer">2592000000</replies-close-in>
|
255
253
|
<written-on type="date">2003-07-16</written-on>
|
256
254
|
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
|
257
|
-
<content type="yaml">--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n</content>
|
258
255
|
<author-email-address>david@loudthinking.com</author-email-address>
|
259
256
|
<parent-id></parent-id>
|
260
257
|
<ad-revenue type="decimal">1.5</ad-revenue>
|
@@ -272,15 +269,11 @@ class XmlTest < Test::Unit::TestCase
|
|
272
269
|
'replies_close_in' => 2592000000,
|
273
270
|
'written_on' => Date.new(2003, 7, 16),
|
274
271
|
'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
|
275
|
-
# Changed this line where the key is :message. The yaml specifies this as a symbol, and who am I to change what you specify
|
276
|
-
# The line in ActiveSupport is
|
277
|
-
# 'content' => { 'message' => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
|
278
|
-
'content' => { :message => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
|
279
272
|
'author_email_address' => "david@loudthinking.com",
|
280
273
|
'parent_id' => nil,
|
281
274
|
'ad_revenue' => BigDecimal("1.50"),
|
282
275
|
'optimum_viewing_angle' => 135.0,
|
283
|
-
'resident' =>
|
276
|
+
'resident' => 'yes',
|
284
277
|
}
|
285
278
|
|
286
279
|
Crack::XML.parse(topic_xml)["topic"].each do |k,v|
|
@@ -487,13 +480,13 @@ class XmlTest < Test::Unit::TestCase
|
|
487
480
|
|
488
481
|
Crack::XML.parse(xml_string)['person'].should == expected_hash
|
489
482
|
end
|
490
|
-
|
483
|
+
|
491
484
|
should "handle an empty xml string" do
|
492
485
|
Crack::XML.parse('').should == {}
|
493
486
|
end
|
494
|
-
|
487
|
+
|
495
488
|
# As returned in the response body by the unfuddle XML API when creating objects
|
496
489
|
should "handle an xml string containing a single space" do
|
497
490
|
Crack::XML.parse(' ').should == {}
|
498
491
|
end
|
499
|
-
end
|
492
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Nunemaker
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2013-01-09 00:00:00 Z
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description:
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements: []
|
77
77
|
|
78
78
|
rubyforge_project: crack
|
79
|
-
rubygems_version: 1.8.
|
79
|
+
rubygems_version: 1.8.10
|
80
80
|
signing_key:
|
81
81
|
specification_version: 3
|
82
82
|
summary: Really simple JSON and XML parsing, ripped from Merb and Rails.
|