tabled 1.1.0 → 1.2.1

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: a8bff1dfe77f793e213ad96a8b29f0680d8a1f51b47af41384467b8846c87482
4
- data.tar.gz: bc34ee68acd27d1525ca10568f32decac36765ba92216992d897f17f1852e40e
3
+ metadata.gz: 78f9a4676c576cb1ebacd2a9a33422a7dd575f6b7107b4680fdda9d592633997
4
+ data.tar.gz: bd69378b7378d739b6dad4c8e42dd59a6f0a4e6155866ed2b6dfa15626a4cb9b
5
5
  SHA512:
6
- metadata.gz: b8d072e93948a3a2f748ef71cc589b9deee8d3ba820c91c421c808335d3e85ef75a82feeb7a1969127c83f263fa872e4a0bc5de0099ab37ae9f01c9f76e1aea1
7
- data.tar.gz: 6db4bf05dbcd226a2b575c8420d7835833de07811580a94fd38a907afab82e9ac2eebc82453fbb8c89ce762f4455ed34a42e458e4988696b024a68d082c62635
6
+ metadata.gz: c3cf2c43b66dc90d117eedcd5620c467845430972731c7243a3c0f7a02cb9ef8546b4ee0ee0870ed5cbd54934236e254a6d1ec132d4101be2cf792ac53f4e694
7
+ data.tar.gz: 9819cf23969ee6f8979fc70236adf78e0a13b5177daa085b4ebda3a6334297c70feb744e975a4102471410566f27b41219a009a578f00e1da46a3a2d71e70bd7
@@ -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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tabled (1.1.0)
4
+ tabled (1.2.1)
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.
@@ -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)
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.1.0'
5
+ s.version = '1.2.1'
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.1.0
4
+ version: 1.2.1
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-24 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,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.2.33
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: []