leenookx-json-mangler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gitignore +2 -0
- data/History.txt +6 -0
- data/LICENSE +10 -0
- data/Manifest.txt +8 -0
- data/README.rdoc +50 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/features/create.feature +20 -0
- data/features/extraction.feature +34 -0
- data/features/group.feature +21 -0
- data/features/mocks/calais.json +2464 -0
- data/features/mocks/empty.json +0 -0
- data/features/mocks/extraction.json +1 -0
- data/features/mocks/extraction2.json +1 -0
- data/features/mocks/grouped.json +9 -0
- data/features/mocks/non_grouped.json +8 -0
- data/features/mocks/valid.json +23 -0
- data/features/prune.feature +11 -0
- data/features/step_definitions/creation_steps.rb +24 -0
- data/features/step_definitions/extaction_steps.rb +63 -0
- data/features/step_definitions/groups_steps.rb +24 -0
- data/features/step_definitions/prune_steps.rb +10 -0
- data/features/support/env.rb +17 -0
- data/features/test_comparisons/2level_extraction.json +1 -0
- data/features/test_comparisons/array_extraction.json +1 -0
- data/features/test_comparisons/author_extraction.json +1 -0
- data/features/test_comparisons/empty_extraction.json +1 -0
- data/features/test_comparisons/published_extraction.json +1 -0
- data/json-mangler.gemspec +72 -0
- data/lib/json_extractor.rb +173 -0
- data/lib/json_mangler.rb +39 -0
- data/test/test_json_mangler.rb +8 -0
- metadata +87 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gitignore
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright(c) 2009 leenookx
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the .Software.), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED .AS IS., WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= json-mangler
|
2
|
+
|
3
|
+
* http://github.com/leenookx/json-mangler
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A ruby utility that allows mangling of data in the JSON
|
8
|
+
format.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* compact Compacts all duplicated branches.
|
13
|
+
* prune Allows removal of branches.
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
FIX (code sample of usage)
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
* json
|
22
|
+
|
23
|
+
== INSTALL:
|
24
|
+
|
25
|
+
* sudo gem install
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
|
29
|
+
(The MIT License)
|
30
|
+
|
31
|
+
Copyright (c) 2009 leenookx
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'cucumber'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
8
|
+
t.cucumber_opts = "features --format pretty"
|
9
|
+
t.rcov = true
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gemspec|
|
15
|
+
gemspec.name = "json-mangler"
|
16
|
+
gemspec.summary = "JSON data format mangling tools."
|
17
|
+
gemspec.description = "JSON data format mangling tools."
|
18
|
+
gemspec.email = "lnookx@googlemail.com"
|
19
|
+
gemspec.homepage = "http://github.com/leenookx/json-mangler"
|
20
|
+
gemspec.description = "TODO"
|
21
|
+
gemspec.authors = ["lee nookx"]
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# vim: syntax=ruby
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: Creation
|
2
|
+
In order to test that the JSON stream can be parsed
|
3
|
+
As a developer
|
4
|
+
I want to create new mangling objects
|
5
|
+
|
6
|
+
Scenario: Create new JSON Mangler Object
|
7
|
+
Given I already have a valid JSON mock stream
|
8
|
+
When I try and create a mangler object
|
9
|
+
Then the resultant object is valid
|
10
|
+
|
11
|
+
Scenario: Try and create a JSON Mangler object from an empty JSON stream
|
12
|
+
Given I already have an empty JSON mock stream
|
13
|
+
When I try and create a mangler object
|
14
|
+
Then I should get an invalid JSON mangler object
|
15
|
+
|
16
|
+
Scenario: Create new JSON Mangler Object and check the output
|
17
|
+
Given I already have a valid JSON mock stream
|
18
|
+
When I try and create a mangler object
|
19
|
+
Then the output equals the input JSON mock stream
|
20
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: Creation
|
2
|
+
In order to test that we can extract data from the JSON stream
|
3
|
+
As a developer
|
4
|
+
I want to try and extract some tags
|
5
|
+
|
6
|
+
Scenario: Make sure we can't remove any tags unless they exist
|
7
|
+
Given I already have a JSON stream
|
8
|
+
When I try and extract a tag 'non-existant' which doesn't exist
|
9
|
+
Then the resultant JSON is empty
|
10
|
+
|
11
|
+
Scenario: Ensure we can extract simple top-level tags
|
12
|
+
Given I already have a JSON stream
|
13
|
+
When I try and extract the authors name
|
14
|
+
Then the resultant JSON contains the author details
|
15
|
+
|
16
|
+
Scenario: Ensure we can extract simple data forms
|
17
|
+
Given I already have a JSON stream
|
18
|
+
When I try and extract any tags where the publishing date was 1999
|
19
|
+
Then the resultant JSON contains the publishing date
|
20
|
+
|
21
|
+
Scenario: Ensure we can extract data from complicated JSON data
|
22
|
+
Given I already have a complicated JSON stream
|
23
|
+
When I try and extract any tags where the publishing date was 1999
|
24
|
+
Then the resultant JSON contains the publishing date
|
25
|
+
|
26
|
+
Scenario: Ensure that we can extract data from JSON arrays
|
27
|
+
Given I already have a JSON stream
|
28
|
+
When I try and extract data from the keyword array
|
29
|
+
Then the resultant JSON data contains the array
|
30
|
+
|
31
|
+
Scenario: Ensure that multiple levels of data can be returned
|
32
|
+
Given I already have a JSON stream
|
33
|
+
When I try and extract data from the keyword array with a depth of 2
|
34
|
+
Then the result JSON data contains the array and its parent
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Grouping
|
2
|
+
In order to test that the JSON stream can be grouped into common tags
|
3
|
+
As a developer
|
4
|
+
I want to create new mangling objects
|
5
|
+
And then group the data held within them
|
6
|
+
|
7
|
+
Scenario: After grouping the mangling object remains valid
|
8
|
+
Given I already have a valid JSON mock stream containing groups
|
9
|
+
When I group the contents of the mangling object
|
10
|
+
Then the JSON mangler remains valid
|
11
|
+
|
12
|
+
Scenario: After grouping the correct groups are formed
|
13
|
+
Given I already have a valid JSON mock stream containing groups
|
14
|
+
When I group the contents of the mangling object
|
15
|
+
Then the JSON stream is grouped correctly
|
16
|
+
|
17
|
+
Scenario: Trying a group a non-repeating JSON stream makes no difference
|
18
|
+
Given I already have a valid JSON mock stream containing no groups
|
19
|
+
When I group the contents of the mangling object
|
20
|
+
Then the JSON stream remains the same as at the start
|
21
|
+
|