xvert 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a54c0d30f80772c15d6fd5d2f2fd7a2e54b150e16ec7316c4fe977da29df7512
4
- data.tar.gz: d0566e39fc64b7b2b3c464c24e986f6cd70c07ca3e1fd0d39fb56f4409a0b794
3
+ metadata.gz: ff0b4a5b08f0fb5ffc8f9bd9c4a2f13ee5ddeca7c09f7c2687146ed0ddff165e
4
+ data.tar.gz: 9a2dc105504df2c32c3467341eccb7cee0f9407625431ebc272df3dad3656a2a
5
5
  SHA512:
6
- metadata.gz: 1d8f28ff98e037a471d0fc1189513a2baec6aff0fb486c5d08318a1fd44adcbab9063b1f64cdd91e194be3e1cd9182021bb1979f6876ab57a2c287ee2cca7cb3
7
- data.tar.gz: 79125a59034c4020a30c983f2676e902896c42791ca71a44ee134656191db49ea85e446366087c9dfe16f492dc3edcc2db618ca0be611e74a01ee0e2552aabdc
6
+ metadata.gz: 81f03e5fdb5751c48fbc4e7cfaa7e7524f903560a886fcd39315a8c91163f9a198a871328fb6579ccbae1c8bd25d596f59ad18a22519c1f76605be1150cc0a2a
7
+ data.tar.gz: 6df53e051e6e1fc0a234ea88857aa979b256faa2999ba503ad8cd03c54ae304e221fba6b9bb60edabec7bfbcb6cdcd2ef97b32e047a62255fcaf77f5368d280d
data/.rubocop.yml CHANGED
@@ -14,3 +14,7 @@ Style/Documentation:
14
14
 
15
15
  Layout/LineLength:
16
16
  Max: 120
17
+
18
+ Metrics/MethodLength:
19
+ Exclude:
20
+ - 'test/**/*'
data/Gemfile.lock CHANGED
@@ -1,13 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xvert (0.0.4)
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
- Convert between CSV, JSON, YAML, and various other formats.
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
- :construction: TODO :construction:
12
+ ```console
13
+ $ gem install xvert
14
+ ```
8
15
 
9
16
  ## Usage
10
17
 
11
- :construction: TODO :construction:
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](https://opensource.org/licenses/MIT)
32
+ [MIT License](./LICENSE.txt)
16
33
 
17
34
  ## Code of Conduct
18
35
 
data/bin/xvert CHANGED
@@ -2,25 +2,6 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
- require "thor"
6
5
  require "xvert"
7
6
 
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)
7
+ ::Xvert::CLI.start(ARGV)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xvert
4
- VERSION = "0.0.4"
4
+ VERSION = "0.1.0"
5
5
  end
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/json"
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
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": ["github>koki-develop/renovate-config"]
4
+ }
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 CSV, JSON, YAML, and various other formats."
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"
@@ -25,5 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
+ spec.add_runtime_dependency "json", "~> 2.6.0"
28
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"
29
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - koki-develop
@@ -10,6 +10,20 @@ 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
- description: Convert between CSV, JSON, YAML, and various other formats.
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:
@@ -41,9 +83,9 @@ files:
41
83
  - Rakefile
42
84
  - bin/xvert
43
85
  - lib/xvert.rb
44
- - lib/xvert/json.rb
86
+ - lib/xvert/cli.rb
45
87
  - lib/xvert/version.rb
46
- - lib/xvert/yaml.rb
88
+ - renovate.json
47
89
  - sig/xvert.rbs
48
90
  - xvert.gemspec
49
91
  homepage: https://github.com/koki-develop/xvert
data/lib/xvert/json.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Xvert
4
- class << self
5
- def json_to_yaml(text)
6
- JSON.parse(text).to_yaml
7
- end
8
- end
9
- end
data/lib/xvert/yaml.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Xvert
4
- class << self
5
- def yaml_to_json(text)
6
- YAML.safe_load(text).to_json
7
- end
8
- end
9
- end