tabled 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adb359bc58e55473ea7dd7cfa6904958d176941ca5b4fb6681a06dc6fd964969
4
- data.tar.gz: 9b19a8cb5e626295d74ad3c6c688c4c6f239acc978280903046605f3ee35c9ad
3
+ metadata.gz: 5f87e77f21f054305b5292f4f02f81c3edea126d0049dd94139691881c0fd140
4
+ data.tar.gz: 2b816ea5e5dd85ef1cd0af90c40970baf8364453c7aab445b54075f732ae604b
5
5
  SHA512:
6
- metadata.gz: 1e1b1a24376f259ce913a07887d7e13a2bfb6a2475a28440fde93759b6da479d1d36a98acba8476d1e5ed1844b29dc1192ace0694d5c458f4362ee55e8766cc8
7
- data.tar.gz: 675b13f080fb7ed1ce7319028684707b5423096f6a7f355dd96fbba6e69d472f3c320cb6e03d53072234589a67c71aa343868358d841df20fc039ffce9136139
6
+ metadata.gz: e1092ca10cfe3b9a002c8d3a379cf7ca387cfb422607a5075392eab020d7436b5ed83e2b4d35926da6230277221ca6e7a75d040e665a042d5cc60ce6aa2faf54
7
+ data.tar.gz: 26104ad19f5a160519acc10479f644881410b4bf92c5f1ded9e470eb62e58f5c96228bc471e55b7495c0b6cd71fc5a9faf6bfb322e2e716ffb4acc8f217d53a3
@@ -2,23 +2,26 @@ name: CodeMetrics report sending
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ main ]
5
+ branches: [main]
6
6
  pull_request:
7
- branches: [ main ]
7
+ branches: [main]
8
8
 
9
9
  permissions:
10
10
  contents: read
11
11
 
12
12
  jobs:
13
-
14
13
  report_sending:
15
14
  runs-on: ubuntu-latest
16
15
  steps:
17
16
  - uses: actions/checkout@v3
17
+
18
18
  - name: Set up Ruby
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 3.0
21
+ ruby-version: 3.1
22
22
  bundler-cache: true
23
23
 
24
- - run: sh ./sending_report.sh
24
+ - name: Codemetrics sending report
25
+ env:
26
+ CODEMETRICS_TOKEN: ${{ secrets.CODEMETRICS_TOKEN }}
27
+ uses: Rukomoynikov/codemetrics-gh-action@main
@@ -5,23 +5,22 @@
5
5
  # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
6
  # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
7
 
8
- name: Ruby
8
+ name: Static analysis
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ main ]
12
+ branches: [main]
13
13
  pull_request:
14
- branches: [ main ]
14
+ branches: [main]
15
15
 
16
16
  permissions:
17
17
  contents: read
18
18
 
19
19
  jobs:
20
-
21
20
  linters:
22
21
  strategy:
23
22
  matrix:
24
- ruby-version: ['3.0']
23
+ ruby-version: ["3.0"]
25
24
  runs-on: ubuntu-latest
26
25
  steps:
27
26
  - uses: actions/checkout@v3
@@ -37,7 +36,7 @@ jobs:
37
36
  strategy:
38
37
  matrix:
39
38
  os: [ubuntu-latest, macos-latest]
40
- ruby-version: ['2.7', '3.0', '3.1', '3.2']
39
+ ruby-version: ["3.0", "3.1", "3.2"]
41
40
  steps:
42
41
  - uses: actions/checkout@v3
43
42
  - name: Set up Ruby
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
@@ -67,7 +67,11 @@ GEM
67
67
  unicode-display_width (2.4.2)
68
68
 
69
69
  PLATFORMS
70
+ aarch64-linux
71
+ arm64-darwin-2
72
+ arm64-darwin-20
70
73
  arm64-darwin-22
74
+ arm64-darwin-23
71
75
  x86_64-darwin-20
72
76
  x86_64-linux
73
77
 
@@ -79,4 +83,4 @@ DEPENDENCIES
79
83
  tabled!
80
84
 
81
85
  BUNDLED WITH
82
- 2.3.26
86
+ 2.5.11
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017-2023 Max Rukomoynikov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,25 +1,46 @@
1
+ # Tabled
1
2
 
2
3
  [![Gem Version](https://badge.fury.io/rb/tabled.svg)](https://badge.fury.io/rb/tabled) ![CI is pasing for ruby 2.6 - 3.0](https://github.com/rukomoynikov/tabled/actions/workflows/linters.yml/badge.svg) ![Downloads](https://badgen.net/rubygems/dt/tabled)
3
4
 
5
+ Tabled is a versatile gem designed for rendering tabular data in a console. It offers various features to make data presentation simple and customizable.
4
6
 
5
- # Description
6
- Library can be used to render your data to a console. Though it's quite simple, but has many features.
7
+ ## Table of Contents
7
8
 
8
- # How to use
9
- 1. Install the gem `bundle add tabled` or `gem install tabled`
10
- 2. Add to the application `require 'tabled''`
11
- 3. Pass to the application array of rows. Each row may have any amount of columns and optional footer text.
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [Options](#options)
12
+ - [Examples](#examples)
13
+ - [Exporting Data](#exporting-data)
14
+ - [Printing CSV or JSON Files](#printing-csv-or-json-files)
15
+ - [Contributing](#contributing)
12
16
 
13
- ### Params for Tabled instance
14
- Tabled accepts two params. Data which is prohibited and options.
15
- Available options:
16
- 1. `framed` - optional, default is true
17
- 2. `row_separator` - optional, default is `-`. Can be `nil` if you don't need separate rows.
18
- 3. `titles` - optional parameter with list of columns titles
17
+ ## Installation
18
+ ```shell
19
+ bundle add tabled
20
+ # or
21
+ gem install tabled
22
+ ```
23
+
24
+ ## Usage
25
+ To use Tabled in your application, follow these steps:
26
+ 1. Require the gem in your code:
27
+ ```ruby
28
+ require 'tabled'
29
+ ```
30
+ 2. Pass an array of rows to the application. Each row can contain any number of columns and optional footer text.
31
+
32
+ ## Options
33
+ Tabled accepts the following options:
34
+
35
+ - `framed` (optional, default: true): Specify if the output should have frames.
36
+ - `row_separator` (optional, default: "-"): Set the character for row separators or set it to nil if you don't want to separate rows.
37
+ - `titles` (optional): Provide a list of column titles.
38
+
39
+ ## Examples
40
+ Here are some examples to help you get started:
19
41
 
20
- More examples in [demo.rb](./demo.rb)
42
+ ### Simple Data Structure
21
43
 
22
- ### Simple data structure
23
44
  ```ruby
24
45
  data = [
25
46
  ["Helena", "20 years", "Female"],
@@ -27,18 +48,11 @@ data = [
27
48
  ["Alan", "23 years", "Male"],
28
49
  ]
29
50
 
30
- Tabled.new(data, framed: false,
31
- row_separator: nil).print_to_console
51
+ Tabled.new(data, framed: false, row_separator: nil).print_to_console
32
52
  ```
33
53
 
34
- Result
35
- ```shell
36
- Helena 20 years Female
37
- John 18 years Male
38
- Alan 23 years Male
39
- ```
54
+ ### Using Footer Inside a Row
40
55
 
41
- ### Using footer inside a row
42
56
  ```ruby
43
57
  data = [
44
58
  ["Helena", "20 years", "Female"],
@@ -49,43 +63,27 @@ data = [
49
63
  Tabled.new(data, row_separator: nil).print_to_console
50
64
  ```
51
65
 
52
- Result
53
- ```shell
54
- ----------------------------------------------------------------
55
- | Helena 20 years Female |
56
- | John 18 years Male |
57
- | Legendary assassin John Wick (Keanu Reeves). |
58
- | Alan 23 years Male |
59
- ----------------------------------------------------------------
60
- ```
66
+ ## Exporting Data
61
67
 
62
- ### Export data to CSV or JSON file
63
- Passed data can be exported as a file. Available formats are `csv` and `json`. Both parameters are optional. By default, file will be saved in the current directory and with file name `tabled.csv` and file format is `CSV`.
68
+ You can export the data in CSV or JSON formats. By default, the file is saved in the current directory with the file name "tabled.csv" (CSV format).
64
69
 
65
70
  ```ruby
66
- # CSV
67
- data = [
68
- ["Helena", "20 years", "Female"],
69
- ]
70
-
71
- Tabled
72
- .new(data)
73
- .export_to_csv
71
+ # Export to CSV
72
+ Tabled.new(data).export_to_file
74
73
 
75
- # JSON
76
- data = [
77
- ["Helena", "20 years", "Female"],
78
- ]
74
+ # Export to JSON
75
+ Tabled.new(data, titles: ['Name', 'Age', 'Gender']).export_to_file(format: :json)
79
76
 
80
- Tabled
81
- .new(data, titles: ['Name', 'Age', 'Gender'])
82
- .export_to_csv(format: :json)
77
+ # Customize file name
78
+ Tabled.new(data, titles: ['Name', 'Age', 'Gender']).export_to_file(file_name: 'my_file.json')
83
79
  ```
84
80
 
85
- # Printing CSV files to console
86
- As a part of the gem `tabled` binary is included. So, you can basicaly run it like:
81
+ ## Printing CSV or JSON Files
82
+
83
+ As part of the gem, the *tabled* binary is included. You can run it like this:
84
+
87
85
  ```shell
88
- tabled print path_to_csv_file
86
+ tabled print path_to_[csv|json]_file
89
87
  ```
90
88
 
91
89
  # Contributing
@@ -94,3 +92,7 @@ tabled print path_to_csv_file
94
92
  3. Commit your changes (git commit -am 'Add some feature')
95
93
  4. Push to the branch (git push origin my-new-feature)
96
94
  5. Create new Pull Request
95
+
96
+ # Development process in Docker
97
+
98
+ Run `docker compose run --build --rm app bash` to get full packed dev environment for the gem developing.
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,10 @@
1
+ services:
2
+ app:
3
+ build:
4
+ dockerfile_inline: |
5
+ FROM ruby:bullseye
6
+ COPY Gemfile Gemfile.lock tabled.gemspec .
7
+ RUN bundle install
8
+ working_dir: /app
9
+ volumes:
10
+ - ./:/app
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Custom errors for the gem
4
+ class Tabled::FormatError < StandardError # rubocop:disable Style/ClassAndModuleChildren
5
+ def initialize(received_format:)
6
+ @received_format = received_format
7
+ super
8
+ end
9
+
10
+ def message
11
+ "Expected to receive CSV but received #{@received_format}"
12
+ end
13
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'csv'
4
+
4
5
  class Tabled
5
6
  class CSVParser
6
7
  def self.parse(file_path)
@@ -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/lib/tabled.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'template'
4
4
  require_relative 'helpers'
5
5
  require_relative 'content_shaper'
6
6
  require_relative 'file_builders/base_file_builder'
7
+ require_relative 'errors/format_error'
7
8
 
8
9
  class Tabled
9
10
  include BaseFileBuilder
@@ -21,4 +22,10 @@ class Tabled
21
22
  def print_to_console
22
23
  print content.join("\n")
23
24
  end
25
+
26
+ def self.from_csv(csv:, **options)
27
+ raise Tabled::FormatError.new(received_format: csv.class) unless csv.is_a? CSV::Table
28
+
29
+ new(csv.to_a, **options)
30
+ end
24
31
  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.2.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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Rukomoynikov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-06 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -97,15 +97,19 @@ files:
97
97
  - CHANGELOG.md
98
98
  - Gemfile
99
99
  - Gemfile.lock
100
+ - LICENSE.md
100
101
  - README.md
101
102
  - bin/tabled
102
103
  - demo.rb
104
+ - docker-compose.yml
103
105
  - lib/content_shaper.rb
106
+ - lib/errors/format_error.rb
104
107
  - lib/file_builders/base_file_builder.rb
105
108
  - lib/file_builders/csv_file_builder.rb
106
109
  - lib/file_builders/json_file_builder.rb
107
110
  - lib/helpers.rb
108
111
  - lib/parsers/csv_parser.rb
112
+ - lib/parsers/json_parser.rb
109
113
  - lib/tabled.rb
110
114
  - lib/template.rb
111
115
  - sending_report.sh
@@ -116,7 +120,7 @@ licenses:
116
120
  metadata:
117
121
  source_code_uri: https://github.com/Rukomoynikov/tabled
118
122
  rubygems_mfa_required: 'true'
119
- post_install_message:
123
+ post_install_message:
120
124
  rdoc_options: []
121
125
  require_paths:
122
126
  - lib
@@ -131,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
135
  - !ruby/object:Gem::Version
132
136
  version: '0'
133
137
  requirements: []
134
- rubygems_version: 3.2.33
135
- signing_key:
138
+ rubygems_version: 3.5.11
139
+ signing_key:
136
140
  specification_version: 4
137
141
  summary: Library for rendering pretty tables in console
138
142
  test_files: []