convert-serialization 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -0
  3. data/bin/convert-serialization +22 -15
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73503bd0fdb0d1578e3a1c2cb46ca0ecb3e479e867a37ffd858e219c104bfaa3
4
- data.tar.gz: e72e78b2f314ce010f1dbdfea5aca9cd4e0a479be956cfaeaf7ca19f2cab2fbd
3
+ metadata.gz: ed1d9142b94c48a3d73c3c3bc586b7ac3bea1e0dc15165816c0c9dd23a8a0008
4
+ data.tar.gz: 2aaeac71f5aff57a3fc03ffd08eed4d1e77b39998936bc36e6e3633522d821e0
5
5
  SHA512:
6
- metadata.gz: b762692cb670950c9325b7cfb2dfb6bb3634e55c2e83c3f43b33151f6ce0ab41c8e5e931603bba2fc4939fd41679c025ffee283d2eb927bfc60ff407978dbb19
7
- data.tar.gz: a9d4f04cb660010a4d3139f26bdb920655c79fe56698d380806ee186b912fa16fa85a1467d9e77d93330cf0b38c2852b675cde76a7d4aa9827ba1c8ea26f240c
6
+ metadata.gz: 4996c20eda7e4c4406e1e874b7250bba098e3c16967af6e7e0d39db4c25fa3c4ad13a428f9e4351ecfd770a47cfbe2851a2a614b09849dac486d57e25edc9b28
7
+ data.tar.gz: ffb44cb5debcd0fc36a6ea303e1abf8c7a8b3985b350a72543f8792ab97f9293f30de56ea533b71f2c6bc1717734ca509e13805583fc807fb122a86b89fd9765
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
+ ```
@@ -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('-i', '--in INPUT_FORMAT', 'Specifies the input format (msgpack / json / yaml / toml).') do |format|
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('-o', '--out OUTPUT_FORMAT', 'Specifies the output format (msgpack / json / yaml / toml).') do |format|
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'
@@ -52,12 +61,8 @@ begin
52
61
  end
53
62
  when 'toml'
54
63
  lambda do |filename|
55
- require 'tomlib'
56
- file = File.new filename, 'r'
57
- result = Tomlib.load(file.read)
58
- file.close
59
-
60
- result
64
+ require 'toml-rb'
65
+ TomlRB.load_file filename
61
66
  end
62
67
  else
63
68
  raise ArgumentError, 'Unknown input format.'
@@ -90,9 +95,11 @@ begin
90
95
  end
91
96
  when 'toml'
92
97
  lambda do |object, filename|
93
- require 'tomlib'
98
+ raise 'The primary toml block must consist of key-value pairs.' unless object.is_a? Hash
99
+
100
+ require 'toml-rb'
94
101
  file = File.new filename, 'w'
95
- file.write Tomlib.dump(object)
102
+ file.write TomlRB.dump(object)
96
103
  file.close
97
104
  end
98
105
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convert-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Küthe
@@ -11,25 +11,25 @@ cert_chain: []
11
11
  date: 2023-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: tomlib
14
+ name: toml-rb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: '2.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.6.0
22
+ version: '2.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 0.6.0
29
+ version: '2.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.6.0
32
+ version: '2.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: msgpack
35
35
  requirement: !ruby/object:Gem::Requirement