xvert 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +8 -1
- data/README.md +21 -4
- data/bin/xvert +7 -0
- data/lib/xvert/cli.rb +65 -0
- data/lib/xvert/version.rb +1 -1
- data/lib/xvert.rb +62 -2
- data/renovate.json +4 -0
- data/xvert.gemspec +6 -4
- metadata +48 -6
- data/exe/xvert +0 -26
- data/lib/xvert/json.rb +0 -9
- data/lib/xvert/yaml.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff0b4a5b08f0fb5ffc8f9bd9c4a2f13ee5ddeca7c09f7c2687146ed0ddff165e
|
4
|
+
data.tar.gz: 9a2dc105504df2c32c3467341eccb7cee0f9407625431ebc272df3dad3656a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f03e5fdb5751c48fbc4e7cfaa7e7524f903560a886fcd39315a8c91163f9a198a871328fb6579ccbae1c8bd25d596f59ad18a22519c1f76605be1150cc0a2a
|
7
|
+
data.tar.gz: 6df53e051e6e1fc0a234ea88857aa979b256faa2999ba503ad8cd03c54ae304e221fba6b9bb60edabec7bfbcb6cdcd2ef97b32e047a62255fcaf77f5368d280d
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xvert (0.0
|
4
|
+
xvert (0.1.0)
|
5
|
+
json (~> 2.6.0)
|
5
6
|
thor (~> 1.2.0)
|
7
|
+
toml-rb (~> 2.2.0)
|
8
|
+
yaml (~> 0.2.0)
|
6
9
|
|
7
10
|
GEM
|
8
11
|
remote: https://rubygems.org/
|
9
12
|
specs:
|
10
13
|
ast (2.4.2)
|
14
|
+
citrus (3.0.2)
|
11
15
|
json (2.6.3)
|
12
16
|
minitest (5.18.0)
|
13
17
|
parallel (1.23.0)
|
@@ -31,7 +35,10 @@ GEM
|
|
31
35
|
parser (>= 3.2.1.0)
|
32
36
|
ruby-progressbar (1.13.0)
|
33
37
|
thor (1.2.1)
|
38
|
+
toml-rb (2.2.0)
|
39
|
+
citrus (~> 3.0, > 3.0)
|
34
40
|
unicode-display_width (2.4.2)
|
41
|
+
yaml (0.2.1)
|
35
42
|
|
36
43
|
PLATFORMS
|
37
44
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -1,18 +1,35 @@
|
|
1
1
|
# Xvert
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem](https://img.shields.io/gem/v/xvert?logo=ruby&logoColor=%23CC342D)](https://rubygems.org/gems/xvert)
|
4
|
+
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/koki-develop/xvert?logo=codeclimate)](https://codeclimate.com/github/koki-develop/xvert)
|
5
|
+
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/koki-develop/xvert/main.yml?logo=github)](https://github.com/koki-develop/xvert/actions/workflows/main.yml)
|
6
|
+
[![GitHub](https://img.shields.io/github/license/koki-develop/xvert)](./LICENSE.txt)
|
7
|
+
|
8
|
+
Convert between JSON, YAML, TOML, and various other formats.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
7
|
-
|
12
|
+
```console
|
13
|
+
$ gem install xvert
|
14
|
+
```
|
8
15
|
|
9
16
|
## Usage
|
10
17
|
|
11
|
-
|
18
|
+
```
|
19
|
+
$ xvert help
|
20
|
+
Commands:
|
21
|
+
xvert help [COMMAND] # Describe available commands or one specific command
|
22
|
+
xvert jt # Convert JSON to TOML
|
23
|
+
xvert jy # Convert JSON to YAML
|
24
|
+
xvert tj # Convert TOML to JSON
|
25
|
+
xvert ty # Convert TOML to YAML
|
26
|
+
xvert yj # Convert YAML to JSON
|
27
|
+
xvert yt # Convert YAML to TOML
|
28
|
+
```
|
12
29
|
|
13
30
|
## License
|
14
31
|
|
15
|
-
[MIT License](
|
32
|
+
[MIT License](./LICENSE.txt)
|
16
33
|
|
17
34
|
## Code of Conduct
|
18
35
|
|
data/bin/xvert
ADDED
data/lib/xvert/cli.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
module Xvert
|
6
|
+
class CLI < Thor
|
7
|
+
class << self
|
8
|
+
def exit_on_failure?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# JSON => X
|
15
|
+
#
|
16
|
+
|
17
|
+
desc "jy", "Convert JSON to YAML"
|
18
|
+
def jy
|
19
|
+
run(from: :json, to: :yaml)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "jt", "Convert JSON to TOML"
|
23
|
+
def jt
|
24
|
+
run(from: :json, to: :toml)
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# YAML => X
|
29
|
+
#
|
30
|
+
|
31
|
+
desc "yj", "Convert YAML to JSON"
|
32
|
+
def yj
|
33
|
+
run(from: :yaml, to: :json)
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "yt", "Convert YAML to TOML"
|
37
|
+
def yt
|
38
|
+
run(from: :yaml, to: :toml)
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# TOML => X
|
43
|
+
#
|
44
|
+
|
45
|
+
desc "tj", "Convert TOML to JSON"
|
46
|
+
def tj
|
47
|
+
run(from: :toml, to: :json)
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "ty", "Convert TOML to YAML"
|
51
|
+
def ty
|
52
|
+
run(from: :toml, to: :yaml)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def run(from:, to:)
|
58
|
+
puts ::Xvert.convert(input, from: from, to: to)
|
59
|
+
end
|
60
|
+
|
61
|
+
def input
|
62
|
+
$stdin.readlines.join
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/xvert/version.rb
CHANGED
data/lib/xvert.rb
CHANGED
@@ -1,10 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
+
require "toml-rb"
|
4
5
|
require "yaml"
|
5
6
|
require_relative "xvert/version"
|
6
|
-
require_relative "xvert/
|
7
|
-
require_relative "xvert/yaml"
|
7
|
+
require_relative "xvert/cli"
|
8
8
|
|
9
9
|
module Xvert
|
10
|
+
TO_OBJECT_MAP = {
|
11
|
+
json: :json_to_object,
|
12
|
+
yaml: :yaml_to_object,
|
13
|
+
toml: :toml_to_object
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
TO_TEXT_MAP = {
|
17
|
+
json: :object_to_json,
|
18
|
+
yaml: :object_to_yaml,
|
19
|
+
toml: :object_to_toml
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
private_constant :TO_OBJECT_MAP, :TO_TEXT_MAP
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def convert(text, from:, to:)
|
26
|
+
object = to_object(text, format: from)
|
27
|
+
to_text(object, format: to)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_object(text, format:)
|
31
|
+
send(TO_OBJECT_MAP[format], text)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_text(object, format:)
|
35
|
+
send(TO_TEXT_MAP[format], object)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# JSON
|
41
|
+
|
42
|
+
def json_to_object(text)
|
43
|
+
JSON.parse(text)
|
44
|
+
end
|
45
|
+
|
46
|
+
def object_to_json(object)
|
47
|
+
JSON.pretty_generate(object)
|
48
|
+
end
|
49
|
+
|
50
|
+
# YAML
|
51
|
+
|
52
|
+
def yaml_to_object(text)
|
53
|
+
YAML.unsafe_load(text)
|
54
|
+
end
|
55
|
+
|
56
|
+
def object_to_yaml(object)
|
57
|
+
YAML.dump(object)
|
58
|
+
end
|
59
|
+
|
60
|
+
# TOML
|
61
|
+
|
62
|
+
def toml_to_object(text)
|
63
|
+
TomlRB.parse(text)
|
64
|
+
end
|
65
|
+
|
66
|
+
def object_to_toml(object)
|
67
|
+
TomlRB.dump(object)
|
68
|
+
end
|
69
|
+
end
|
10
70
|
end
|
data/renovate.json
ADDED
data/xvert.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["kou.pg.0131@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = "Convert between various formats."
|
12
|
-
spec.description = "Convert between
|
12
|
+
spec.description = "Convert between JSON, YAML, TOML, and various other formats."
|
13
13
|
spec.homepage = "https://github.com/koki-develop/xvert"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.6.0"
|
@@ -19,12 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.files = Dir.chdir(__dir__) do
|
21
21
|
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:
|
22
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
23
23
|
end
|
24
24
|
end
|
25
|
-
spec.
|
26
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
+
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
27
26
|
spec.require_paths = ["lib"]
|
28
27
|
|
28
|
+
spec.add_runtime_dependency "json", "~> 2.6.0"
|
29
29
|
spec.add_runtime_dependency "thor", "~> 1.2.0"
|
30
|
+
spec.add_runtime_dependency "toml-rb", "~> 2.2.0"
|
31
|
+
spec.add_runtime_dependency "yaml", "~> 0.2.0"
|
30
32
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xvert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- koki-develop
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.6.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: thor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,7 +38,35 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: 1.2.0
|
27
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: toml-rb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yaml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.0
|
69
|
+
description: Convert between JSON, YAML, TOML, and various other formats.
|
28
70
|
email:
|
29
71
|
- kou.pg.0131@gmail.com
|
30
72
|
executables:
|
@@ -39,11 +81,11 @@ files:
|
|
39
81
|
- LICENSE.txt
|
40
82
|
- README.md
|
41
83
|
- Rakefile
|
42
|
-
-
|
84
|
+
- bin/xvert
|
43
85
|
- lib/xvert.rb
|
44
|
-
- lib/xvert/
|
86
|
+
- lib/xvert/cli.rb
|
45
87
|
- lib/xvert/version.rb
|
46
|
-
-
|
88
|
+
- renovate.json
|
47
89
|
- sig/xvert.rbs
|
48
90
|
- xvert.gemspec
|
49
91
|
homepage: https://github.com/koki-develop/xvert
|
data/exe/xvert
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
require "thor"
|
6
|
-
require "xvert"
|
7
|
-
|
8
|
-
class CLI < Thor
|
9
|
-
class << self
|
10
|
-
def exit_on_failure?
|
11
|
-
true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "jy", "Convert JSON to YAML"
|
16
|
-
def jy
|
17
|
-
puts Xvert.json_to_yaml($stdin.readlines.join)
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "yj", "Convert YAML to JSON"
|
21
|
-
def yj
|
22
|
-
puts Xvert.yaml_to_json($stdin.readlines.join)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
CLI.start(ARGV)
|
data/lib/xvert/json.rb
DELETED