tabled 1.1.0 → 1.2.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 +4 -4
- data/.github/workflows/codemetrics.yml +8 -5
- data/.github/workflows/linters.yml +5 -6
- data/Gemfile.lock +5 -1
- data/LICENSE.md +20 -0
- data/README.md +54 -52
- data/docker-compose.yml +10 -0
- data/lib/errors/format_error.rb +13 -0
- data/lib/parsers/csv_parser.rb +1 -0
- data/lib/tabled.rb +7 -0
- data/tabled.gemspec +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f87e77f21f054305b5292f4f02f81c3edea126d0049dd94139691881c0fd140
|
4
|
+
data.tar.gz: 2b816ea5e5dd85ef1cd0af90c40970baf8364453c7aab445b54075f732ae604b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: [
|
5
|
+
branches: [main]
|
6
6
|
pull_request:
|
7
|
-
branches: [
|
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.
|
21
|
+
ruby-version: 3.1
|
22
22
|
bundler-cache: true
|
23
23
|
|
24
|
-
-
|
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:
|
8
|
+
name: Static analysis
|
9
9
|
|
10
10
|
on:
|
11
11
|
push:
|
12
|
-
branches: [
|
12
|
+
branches: [main]
|
13
13
|
pull_request:
|
14
|
-
branches: [
|
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: [
|
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: [
|
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/Gemfile.lock
CHANGED
@@ -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.
|
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
|
[](https://badge.fury.io/rb/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
|
-
|
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
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
86
|
-
|
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
|
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/docker-compose.yml
ADDED
@@ -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
|
data/lib/parsers/csv_parser.rb
CHANGED
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.
|
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.
|
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:
|
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,10 +97,13 @@ 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
|
@@ -117,7 +120,7 @@ licenses:
|
|
117
120
|
metadata:
|
118
121
|
source_code_uri: https://github.com/Rukomoynikov/tabled
|
119
122
|
rubygems_mfa_required: 'true'
|
120
|
-
post_install_message:
|
123
|
+
post_install_message:
|
121
124
|
rdoc_options: []
|
122
125
|
require_paths:
|
123
126
|
- lib
|
@@ -132,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
135
|
- !ruby/object:Gem::Version
|
133
136
|
version: '0'
|
134
137
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
138
|
+
rubygems_version: 3.5.11
|
139
|
+
signing_key:
|
137
140
|
specification_version: 4
|
138
141
|
summary: Library for rendering pretty tables in console
|
139
142
|
test_files: []
|