jsoncrossreference 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jsoncrossreference.rb +43 -0
- metadata +47 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'datacalc'
|
2
|
+
|
3
|
+
class JSONCrossreference
|
4
|
+
|
5
|
+
def initialize(input1, input2)
|
6
|
+
@input1 = input1
|
7
|
+
@input2 = input2
|
8
|
+
@output = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
# What: Cross-references fields in two files
|
12
|
+
# Input: Variable number of arrays with name of fields to compare
|
13
|
+
# Output: JSON with matches
|
14
|
+
# Limitations: Only returns data from one file. Matching multiple fields functions as && not ||. Only takes 2 files input
|
15
|
+
def compare(*fieldnames)
|
16
|
+
if JSON.parse(File.read(@input2)).length < JSON.parse(File.read(@input1)).length
|
17
|
+
file1 = JSON.parse(File.read(@input2))
|
18
|
+
file1length = file1.length
|
19
|
+
file2 = @input1
|
20
|
+
|
21
|
+
tmparray = Array.new
|
22
|
+
fieldnames.each do |field|
|
23
|
+
tmparray.push([field[1], field[0]])
|
24
|
+
end
|
25
|
+
fieldnames = tmparray
|
26
|
+
else
|
27
|
+
file1 = JSON.parse(File.read(@input1))
|
28
|
+
file1length = file1.length
|
29
|
+
file2 = @input2
|
30
|
+
end
|
31
|
+
|
32
|
+
tmpfile = Array.new
|
33
|
+
(0..file1length-1).each do |l|
|
34
|
+
fieldnames.each do |field|
|
35
|
+
value = (file1[l])[field[0]]
|
36
|
+
matchnames = [field[1], value]
|
37
|
+
m = DataCalc.new(file2)
|
38
|
+
tmpfile << m.match(matchnames)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@output = tmpfile.to_json
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsoncrossreference
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- M. C. McGrath
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Crossreferences JSONs and returns the matches
|
15
|
+
email: shidash@shidash.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/jsoncrossreference.rb
|
21
|
+
homepage: https://github.com/Shidash/JSONCrossreference
|
22
|
+
licenses:
|
23
|
+
- GPL
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Crossreferences JSONs
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|