jsontrim 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/jsontrim.gemspec +2 -2
- data/lib/jsontrim.rb +5 -4
- data/test/jsontrim_test.rb +12 -12
- metadata +2 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/jsontrim.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jsontrim}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Levin Alexander"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-28}
|
13
13
|
s.description = %q{remove unimportant elements from a json object}
|
14
14
|
s.email = %q{mail@levinalex.net}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/jsontrim.rb
CHANGED
@@ -51,9 +51,10 @@ class JSONTrim
|
|
51
51
|
end
|
52
52
|
|
53
53
|
js = JSON.pretty_generate(obj)
|
54
|
-
js = js.gsub('"IGN_HSH"', "{
|
55
|
-
js = js.gsub('"IGN_ARY"', "[
|
56
|
-
js = js.gsub('"
|
54
|
+
js = js.gsub('"IGN_HSH"', "{ /*...*/ }")
|
55
|
+
js = js.gsub('"IGN_ARY"', "[ /*...*/ ]")
|
56
|
+
js = js.gsub('"IGN_CDR"', "// ...")
|
57
|
+
js = js.gsub('"IGN"', '"..."')
|
57
58
|
end
|
58
59
|
|
59
60
|
# recursively prune the current ruby object with the given rules
|
@@ -76,7 +77,7 @@ class JSONTrim
|
|
76
77
|
end if data[name]
|
77
78
|
elsif key =~ /^\+$/
|
78
79
|
if Array === data
|
79
|
-
data = [data.first, "
|
80
|
+
data = [data.first, "IGN_CDR"]
|
80
81
|
end
|
81
82
|
elsif key =~ /^\*$/
|
82
83
|
if Array === data
|
data/test/jsontrim_test.rb
CHANGED
@@ -22,35 +22,35 @@ class JsontrimTest < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
should "distinguish between arrays and hashes" do
|
25
|
-
assert_equal %Q({\n "foo": {
|
25
|
+
assert_equal %Q({\n "foo": { /*...*/ }\n}),
|
26
26
|
JSONTrim.cut(%q({"foo" : { "bar": "fred"}}), :ignore => ["!foo"])
|
27
|
-
assert_equal %Q({\n "foo": [
|
27
|
+
assert_equal %Q({\n "foo": [ /*...*/ ]\n}),
|
28
28
|
JSONTrim.cut(%q({"foo" : [ "bar", "fred"]}), :ignore => ["!foo"])
|
29
|
-
assert_equal %Q({\n "foo":
|
29
|
+
assert_equal %Q({\n "foo": "..."\n}),
|
30
30
|
JSONTrim.cut(%q({"foo" : 3}), :ignore => ["!foo"])
|
31
31
|
end
|
32
32
|
|
33
33
|
should "work for nested attributes" do
|
34
|
-
assert_equal %Q({\n "foo": {\n "bar": {
|
34
|
+
assert_equal %Q({\n "foo": {\n "bar": { /*...*/ }\n }\n}),
|
35
35
|
JSONTrim.cut(%q({"foo" : { "bar": {"f":3}}}), :ignore => ["foo:!bar"])
|
36
36
|
|
37
|
-
assert_equal %Q({\n "foo": {\n "bar":
|
37
|
+
assert_equal %Q({\n "foo": {\n "bar": "..."\n }\n}),
|
38
38
|
JSONTrim.cut(%q({"foo" : { "bar": 3}}), :ignore => ["foo:!bar"])
|
39
39
|
end
|
40
40
|
|
41
41
|
should "not alter json if ignored thing does not exist" do
|
42
|
-
assert_equal %Q({\n "foo": {
|
42
|
+
assert_equal %Q({\n "foo": { /*...*/ }\n}),
|
43
43
|
JSONTrim.cut(%q({"foo" : { "bar": "fred"}}),
|
44
44
|
:ignore => ["!foo", "!doesnotexist", "foo:!doesnotexist"])
|
45
45
|
end
|
46
46
|
|
47
47
|
should "allow ignoring of subelements of arrays" do
|
48
|
-
assert_equal_ws %Q({"foo":[{"bar": {
|
48
|
+
assert_equal_ws %Q({"foo":[{"bar": { /*...*/ }},{"bar": "..."}]}),
|
49
49
|
JSONTrim.cut(%q({"foo" : [{ "bar": {"baz":3}}, {"bar":3}]}), :ignore => ["foo:*:!bar"])
|
50
50
|
end
|
51
51
|
|
52
52
|
should "allow ignoring of arrays" do
|
53
|
-
assert_equal %Q({\n "foo": [\n "bar",\n ...\n ]\n}),
|
53
|
+
assert_equal %Q({\n "foo": [\n "bar",\n // ...\n ]\n}),
|
54
54
|
JSONTrim.cut(%q({"foo": ["bar", "baz", "fred"]}),
|
55
55
|
:ignore => ["foo:+"])
|
56
56
|
end
|
@@ -73,18 +73,18 @@ class JsontrimTest < Test::Unit::TestCase
|
|
73
73
|
expected = <<-EOF
|
74
74
|
{
|
75
75
|
"foo": {
|
76
|
-
"two":
|
76
|
+
"two": "...",
|
77
77
|
"three": {
|
78
|
-
"b": [
|
78
|
+
"b": [ /*...*/ ]
|
79
79
|
},
|
80
80
|
"one": {
|
81
81
|
"a": 1,
|
82
|
-
"b": {
|
82
|
+
"b": { /*...*/ }
|
83
83
|
}
|
84
84
|
},
|
85
85
|
"bar": [
|
86
86
|
1,
|
87
|
-
...
|
87
|
+
// ...
|
88
88
|
]
|
89
89
|
}
|
90
90
|
EOF
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsontrim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Levin Alexander
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-28 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|