tabled 1.0.0 → 1.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: adb359bc58e55473ea7dd7cfa6904958d176941ca5b4fb6681a06dc6fd964969
4
- data.tar.gz: 9b19a8cb5e626295d74ad3c6c688c4c6f239acc978280903046605f3ee35c9ad
3
+ metadata.gz: a8bff1dfe77f793e213ad96a8b29f0680d8a1f51b47af41384467b8846c87482
4
+ data.tar.gz: bc34ee68acd27d1525ca10568f32decac36765ba92216992d897f17f1852e40e
5
5
  SHA512:
6
- metadata.gz: 1e1b1a24376f259ce913a07887d7e13a2bfb6a2475a28440fde93759b6da479d1d36a98acba8476d1e5ed1844b29dc1192ace0694d5c458f4362ee55e8766cc8
7
- data.tar.gz: 675b13f080fb7ed1ce7319028684707b5423096f6a7f355dd96fbba6e69d472f3c320cb6e03d53072234589a67c71aa343868358d841df20fc039ffce9136139
6
+ metadata.gz: b8d072e93948a3a2f748ef71cc589b9deee8d3ba820c91c421c808335d3e85ef75a82feeb7a1969127c83f263fa872e4a0bc5de0099ab37ae9f01c9f76e1aea1
7
+ data.tar.gz: 6db4bf05dbcd226a2b575c8420d7835833de07811580a94fd38a907afab82e9ac2eebc82453fbb8c89ce762f4455ed34a42e458e4988696b024a68d082c62635
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
- # on 2023-09-06 20:39:31 UTC using RuboCop version 1.56.2.
3
+ # on 2023-09-24 10:40:26 UTC using RuboCop version 1.56.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -57,18 +57,22 @@ RSpec/ExampleLength:
57
57
  - 'spec/integration/file_builders/export_json_spec.rb'
58
58
  - 'spec/unit/tabled_spec.rb'
59
59
 
60
- # Offense count: 1
61
- RSpec/MultipleDescribes:
60
+ # Offense count: 2
61
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
62
+ # Include: **/*_spec*rb*, **/spec/**/*
63
+ RSpec/FilePath:
62
64
  Exclude:
63
- - 'spec/integration/tabled_spec.rb'
65
+ - 'spec/integration/print_files/print_csv_spec.rb'
66
+ - 'spec/integration/print_files/print_json_spec.rb'
64
67
 
65
- # Offense count: 7
66
- RSpec/RepeatedDescription:
68
+ # Offense count: 4
69
+ # Configuration parameters: Max, AllowedGroups.
70
+ RSpec/NestedGroups:
67
71
  Exclude:
68
- - 'spec/integration/tabled_spec.rb'
69
- - 'spec/unit/tabled_spec.rb'
72
+ - 'spec/integration/print_files/print_csv_spec.rb'
73
+ - 'spec/integration/print_files/print_json_spec.rb'
70
74
 
71
- # Offense count: 12
75
+ # Offense count: 13
72
76
  # Configuration parameters: AllowedConstants.
73
77
  Style/Documentation:
74
78
  Exclude:
@@ -81,5 +85,14 @@ Style/Documentation:
81
85
  - 'lib/file_builders/json_file_builder.rb'
82
86
  - 'lib/helpers.rb'
83
87
  - 'lib/parsers/csv_parser.rb'
88
+ - 'lib/parsers/json_parser.rb'
84
89
  - 'lib/tabled.rb'
85
90
  - 'lib/template.rb'
91
+
92
+ # Offense count: 1
93
+ # This cop supports safe autocorrection (--autocorrect).
94
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
95
+ # URISchemes: http, https
96
+ Layout/LineLength:
97
+ Exclude:
98
+ - 'spec/unit/tabled_spec.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tabled (0.0.6)
4
+ tabled (1.1.0)
5
5
  dry-cli
6
6
 
7
7
  GEM
data/bin/tabled CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative '../lib/tabled'
5
5
  require_relative '../lib/parsers/csv_parser'
6
+ require_relative '../lib/parsers/json_parser'
6
7
  require 'dry/cli'
7
8
  require 'pathname'
8
9
 
@@ -19,12 +20,34 @@ module TabledCli
19
20
  def call(input: nil, **)
20
21
  return p 'File must be provided' if input.nil?
21
22
  return p 'File doesn\'t exist' unless File.exist?(Pathname.new(input))
23
+ return p 'Unsupported file format' unless %w[.csv .json].include?(File.extname(Pathname.new(input)).downcase)
22
24
 
23
- Tabled.new(Tabled::CSVParser.parse(Pathname.new(input))).print_to_console
25
+ file = Pathname.new(input)
26
+
27
+ $stdout << case File.extname(file).downcase
28
+ when '.csv'
29
+ print_csv(file)
30
+ when '.json'
31
+ print_json(file)
32
+ end
33
+ end
34
+
35
+ def print_csv(input)
36
+ Tabled
37
+ .new(Tabled::CSVParser.parse(Pathname.new(input)))
38
+ .print_to_console
39
+ end
40
+
41
+ def print_json(input)
42
+ titles, values = Tabled::JSONParser.parse(Pathname.new(input))
43
+
44
+ Tabled
45
+ .new(values, titles: titles)
46
+ .print_to_console
24
47
  end
25
48
  end
26
49
 
27
- register 'print', Print, aliases: ['p', '-p', '--print']
50
+ register 'print', Print, aliases: %w[p -p --print]
28
51
  end
29
52
  end
30
53
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ class Tabled
5
+ class JSONParser
6
+ def self.parse(file_path)
7
+ file = File.read(file_path)
8
+ json_entries = ::JSON.parse(file)
9
+
10
+ unless json_entries.is_a?(Array) && json_entries.first.is_a?(Hash)
11
+ raise ArgumentError, 'Invalid JSON format. Expected an array of objects.'
12
+ end
13
+
14
+ [json_entries.first.keys, json_entries.map(&:values)]
15
+ end
16
+ end
17
+ end
data/tabled.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'tabled'
5
- s.version = '1.0.0'
5
+ s.version = '1.1.0'
6
6
  s.summary = 'Library for rendering pretty tables in console'
7
7
  s.description = 'Library can be used to render your data to a console. Being quite simple it has many features.'
8
8
  s.authors = ['Max Rukomoynikov']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabled
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Rukomoynikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-06 00:00:00.000000000 Z
11
+ date: 2023-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -106,6 +106,7 @@ files:
106
106
  - lib/file_builders/json_file_builder.rb
107
107
  - lib/helpers.rb
108
108
  - lib/parsers/csv_parser.rb
109
+ - lib/parsers/json_parser.rb
109
110
  - lib/tabled.rb
110
111
  - lib/template.rb
111
112
  - sending_report.sh