convert-serialization 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/bin/convert-serialization +16 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5b01a68267da31477f68a90baf242da8578c3c437b967033c3e122d0ea53d53
|
4
|
+
data.tar.gz: 026cb7ee8263f881e784511e2d06a367ad3485f3bb25e6f4202312fa72e4eb1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbb91b8151139278914d1fc25c0a1d6cfe3a98ff07c3561d1bc9a066041a040fec4a47ea1f835a21918a985691c8a891ad5016cb474efd5c450527df598fe3f
|
7
|
+
data.tar.gz: 013e29910eed6aeaf083b9df42c8a0bce3f2754e74b820dcd3acd44d0d3c254707b697d521631c27899cff421ed0365a49175522b048c2e0c34e9c7d8cc56cdb
|
data/README.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
1
|
# convert-serialization
|
2
2
|
|
3
3
|
A simple Ruby script that can convert between different formats (msgpack / json / yaml / toml).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```
|
8
|
+
$ cat test.json
|
9
|
+
{"hello":"world","numbers":[1,2,3,4,5]}
|
10
|
+
$ convert-serialization -s json -d toml -i test.json -o test.toml
|
11
|
+
Conversion successful!
|
12
|
+
$ cat test.toml
|
13
|
+
hello = "world"
|
14
|
+
numbers = [ 1, 2, 3, 4, 5 ]
|
15
|
+
$ convert-serialization -s toml -d msgpack -i test.toml -o test.msgpack
|
16
|
+
Conversion successful!
|
17
|
+
$ hexdump -C test.msgpack
|
18
|
+
00000000 82 a5 68 65 6c 6c 6f a5 77 6f 72 6c 64 a7 6e 75 |..hello.world.nu|
|
19
|
+
00000010 6d 62 65 72 73 95 01 02 03 04 05 |mbers......|
|
20
|
+
0000001b
|
21
|
+
```
|
data/bin/convert-serialization
CHANGED
@@ -7,32 +7,41 @@ begin
|
|
7
7
|
|
8
8
|
input_format = nil
|
9
9
|
output_format = nil
|
10
|
+
input_file = nil
|
11
|
+
output_file = nil
|
10
12
|
OptionParser.new do |opts|
|
11
13
|
opts.banner = 'Usage: convert-serialization [options] input_file output_file'
|
12
14
|
|
13
|
-
opts.on('-
|
15
|
+
opts.on('-s', '--inf INPUT_FORMAT', 'Specifies the input format (msgpack / json / yaml / toml).') do |format|
|
14
16
|
input_format = format
|
15
17
|
end
|
16
18
|
|
17
|
-
opts.on('-
|
19
|
+
opts.on('-d', '--outf OUTPUT_FORMAT', 'Specifies the output format (msgpack / json / yaml / toml).') do |format|
|
18
20
|
output_format = format
|
19
21
|
end
|
22
|
+
|
23
|
+
opts.on('-i', '--in INPUT_FILE', 'Specifies the input file.') do |file|
|
24
|
+
input_file = file
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-o', '--out OUTPUT_FILE', 'Specifies the output file.') do |file|
|
28
|
+
output_file = file
|
29
|
+
end
|
20
30
|
end.parse!
|
21
31
|
|
22
32
|
raise ArgumentError, 'Input format missing.' unless input_format
|
23
33
|
raise ArgumentError, 'Output format missing.' unless output_format
|
24
|
-
|
25
|
-
input_file = ARGV.shift
|
26
|
-
output_file = ARGV.shift
|
27
|
-
|
28
34
|
raise ArgumentError, 'Input file is missing.' unless input_file
|
29
35
|
raise ArgumentError, 'Output file is missing.' unless output_file
|
30
36
|
|
31
37
|
input_format.strip!
|
32
38
|
input_format.downcase!
|
33
|
-
|
34
39
|
output_format.strip!
|
35
40
|
output_format.downcase!
|
41
|
+
input_file.strip!
|
42
|
+
input_file.downcase!
|
43
|
+
output_file.strip!
|
44
|
+
output_file.downcase!
|
36
45
|
|
37
46
|
in_handler = case input_format
|
38
47
|
when 'msgpack'
|