fconverter 0.0.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fconverter.rb +28 -2
  3. metadata +58 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7cfd79420d70139a493fefb631aba77bcba6f08ecccc7b41e704175c4d4b80a
4
- data.tar.gz: '0778c789bf898d104d75faa3ec2499411115f905721e3f0ec1130ca4d0252bda'
3
+ metadata.gz: 8fc5174a2280a9e6a4e03f6a43cad23b49809ca814cf49bd3b276c8810ad0046
4
+ data.tar.gz: c2accd837b1920b3c63a49cff1b6051b485dd7025cf3e29fecdb6dc61862d6d7
5
5
  SHA512:
6
- metadata.gz: 92ccb982cc2e44354d24e9f090b3154ba28785167085f7e477b84c71bc9d7bccbebacb912e8df3e4f81a1dec077124afb179e2dc6d622ce92108b29e9ee82504
7
- data.tar.gz: 1222981c53ee4963f339dbec8338efe5945758ec550bd1eea9ad99e3874b9cf6eeb46bb7edc6ba58e22befa7ed845a3ef7f3b55f3b858d5f2decc3b1b1211375
6
+ metadata.gz: c550980c1b4c2cd912783f714df09073281e2dd1a08f410fbb1b97d91d59a1174c8ebce53a371aa08b0a7ce489aecc1843f49113f290db07288a8457f527400d
7
+ data.tar.gz: f20f5800520db3bf741c80a7dc7436839fdae261754a83644b9446316bf19ba99da1da504396e04131a0b094d3a9dc2d56e9f179426c634c0dc8579662413c75
data/lib/fconverter.rb CHANGED
@@ -3,6 +3,16 @@
3
3
  require 'thor'
4
4
  require 'csv'
5
5
  require 'json'
6
+ require 'tty-prompt'
7
+
8
+ def check_output_ext(output_path, target_ext)
9
+ output_ext = output_path.split('.')[-1]
10
+ if output_ext != target_ext
11
+ output_path = output_path.sub(/\.[^.]+\z/, ".#{target_ext}")
12
+ puts "Your target extension doesn't match the target file name. The new output path is #{output_path}"
13
+ end
14
+ return output_path
15
+ end
6
16
 
7
17
  def convert_csv_to_json(input_path, output_path)
8
18
  json_array = []
@@ -17,6 +27,8 @@ def convert_csv_to_json(input_path, output_path)
17
27
  json_array << json_object
18
28
  end
19
29
 
30
+ output_path = check_output_ext(output_path, 'json')
31
+
20
32
  File.write(output_path, JSON.pretty_generate(json_array))
21
33
  end
22
34
 
@@ -25,6 +37,9 @@ def convert_json_to_csv(input_path, output_path)
25
37
  json_array = JSON.parse(json_content)
26
38
  headers = json_array.first.keys
27
39
 
40
+ output_path = check_output_ext(output_path, 'csv')
41
+
42
+
28
43
  CSV.open(output_path, 'w') do |csv|
29
44
  # Écrire les en-têtes dans le fichier CSV
30
45
  csv << headers
@@ -39,8 +54,19 @@ end
39
54
 
40
55
  class ConverterCLI < Thor
41
56
 
42
- desc "convert INPUT TYPE OUTPUT", "convert a file at INPUT path to a new TYPE and save at OUTPUT path"
43
- def convert(input, type, output)
57
+ desc "convert", "convert a file from user provided INPUT path to a new TYPE and save at user provided OUTPUT path"
58
+ def convert
59
+ prompt = TTY::Prompt.new
60
+
61
+ input = prompt.ask("Quel est le chemin du fichier à convertir?")
62
+ input_ext = input.split('.')[-1]
63
+
64
+ file_types = ["json", "csv"]
65
+ file_types.delete(input_ext)
66
+
67
+ type = prompt.select("Quel est le type de fichier de sortie souhaité?", file_types)
68
+ output = prompt.ask("Où souhaitez-vous sauvegarder le nouveau fichier?")
69
+
44
70
  if type === 'json'
45
71
  convert_csv_to_json(input, output)
46
72
  elsif type === 'csv'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fconverter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis VIVIER
@@ -9,7 +9,63 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-07-11 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: csv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
13
69
  description: A file converter with many options.
14
70
  email: alexis@nevertoolate.studio
15
71
  executables: