visual_array 0.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 +7 -0
- data/README.md +121 -0
- data/Rakefile +4 -0
- data/lib/visual_array/version.rb +5 -0
- data/lib/visual_array.rb +57 -0
- data/sig/visual_array.rbs +4 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd21265c03d6ce6703f568a354c3138f64d497c72193f73562f873ccdfa49cf1
|
4
|
+
data.tar.gz: 5665bf958cc7e1d0ea7f7d7e0d36ad79b561c69719c64d496bec2712c79b819d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a76ecda7711c46fb1bcdc837313ac5844b4d77c250f2b79a9631e5c5fc9d680c38fe15da23fb1410b30c61d7eabf83b76ee20bd860859df209744a6e0c786ee
|
7
|
+
data.tar.gz: 19981713790f9e9f4c6fef2e3926b10d64183c514f60621a89bb98a58f7361ed6110ee75f9e47274ca52a1bcb07515a94e60f28170e15a531363c74ff8260ba5
|
data/README.md
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# VisualArray
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
**VisualArray** is a Ruby gem that displays arrays in a structured, visually appealing tabular format. It supports **1D, 2D, and multi-dimensional arrays** with options for customizing text **color**.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle add visual_array
|
13
|
+
```
|
14
|
+
|
15
|
+
Or install it manually:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
gem install visual_array
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Basic Example
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'visual_array'
|
27
|
+
|
28
|
+
VisualArray.display([1, 2, 3, 4])
|
29
|
+
```
|
30
|
+
|
31
|
+
**Output:**
|
32
|
+
```
|
33
|
+
+---+---+---+---+
|
34
|
+
| 1 | 2 | 3 | 4 |
|
35
|
+
+---+---+---+---+
|
36
|
+
```
|
37
|
+
|
38
|
+
### 2D Array Example
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
VisualArray.display([
|
42
|
+
[1, 2],
|
43
|
+
[3, 4]
|
44
|
+
])
|
45
|
+
```
|
46
|
+
|
47
|
+
**Output:**
|
48
|
+
```
|
49
|
+
+-----+-----+
|
50
|
+
| 1 | 2 |
|
51
|
+
| 3 | 4 |
|
52
|
+
+-----+-----+
|
53
|
+
```
|
54
|
+
|
55
|
+
### Multi-Dimensional Array Example
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
VisualArray.display([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
|
59
|
+
```
|
60
|
+
|
61
|
+
**Output:**
|
62
|
+
```
|
63
|
+
Dimension 1, Index 0:
|
64
|
+
+-----+-----+
|
65
|
+
| 1 | 2 |
|
66
|
+
| 3 | 4 |
|
67
|
+
+-----+-----+
|
68
|
+
|
69
|
+
Dimension 1, Index 1:
|
70
|
+
+-----+-----+
|
71
|
+
| 5 | 6 |
|
72
|
+
| 7 | 8 |
|
73
|
+
+-----+-----+
|
74
|
+
```
|
75
|
+
|
76
|
+
### Customizing Color
|
77
|
+
|
78
|
+
You can pass optional `color` parameter:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
VisualArray.display(
|
82
|
+
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]],
|
83
|
+
color: 'blue'
|
84
|
+
)
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
bin/setup
|
93
|
+
```
|
94
|
+
|
95
|
+
to install dependencies. Use `bin/console` for an interactive session.
|
96
|
+
|
97
|
+
To install this gem locally:
|
98
|
+
|
99
|
+
```bash
|
100
|
+
bundle exec rake install
|
101
|
+
```
|
102
|
+
|
103
|
+
To release a new version:
|
104
|
+
|
105
|
+
1. Update the version in `version.rb`.
|
106
|
+
2. Run:
|
107
|
+
|
108
|
+
```bash
|
109
|
+
bundle exec rake release
|
110
|
+
```
|
111
|
+
|
112
|
+
This will create a git tag, push commits, and publish the gem to [RubyGems](https://rubygems.org).
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
Bug reports and pull requests are welcome at [GitHub](https://github.com/chandu89/visual_array).
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
This project is available under the [MIT License](LICENSE.txt).
|
121
|
+
|
data/Rakefile
ADDED
data/lib/visual_array.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
module VisualArray
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def display(array, color: "green")
|
9
|
+
raise Error, "Input must be an array" unless array.is_a?(Array)
|
10
|
+
|
11
|
+
dimensions = array_dimensions(array)
|
12
|
+
|
13
|
+
case dimensions
|
14
|
+
when 1
|
15
|
+
display_1d(array, color)
|
16
|
+
when 2
|
17
|
+
display_2d(array, color)
|
18
|
+
else
|
19
|
+
display_multi_d(array, color)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def array_dimensions(array)
|
26
|
+
return 0 unless array.is_a?(Array)
|
27
|
+
1 + array.map { |sub| array_dimensions(sub) }.max.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def display_1d(array, color)
|
31
|
+
table = Terminal::Table.new do |t|
|
32
|
+
t.headings = [Rainbow("Index").cyan, Rainbow("Value").yellow]
|
33
|
+
array.each_with_index { |val, i| t.add_row([i, Rainbow(val).send(color)]) }
|
34
|
+
end
|
35
|
+
puts table
|
36
|
+
end
|
37
|
+
|
38
|
+
def display_2d(array, color)
|
39
|
+
table = Terminal::Table.new do |t|
|
40
|
+
column_headers = [" "] + (0...array.first.size).map { |i| Rainbow("Col #{i}").cyan }
|
41
|
+
t.add_row(column_headers)
|
42
|
+
t.add_separator
|
43
|
+
array.each_with_index do |row, i|
|
44
|
+
t.add_row([Rainbow("Row #{i}").yellow] + row.map { |val| Rainbow(val).send(color) })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
puts table
|
48
|
+
end
|
49
|
+
|
50
|
+
def display_multi_d(array, color, depth = 0)
|
51
|
+
array.each_with_index do |sub_array, index|
|
52
|
+
puts Rainbow("\nDimension #{depth + 1}, Index #{index}:\n").magenta.bright
|
53
|
+
display(sub_array, color: color)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visual_array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chandanchoubey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: VisualArray provides an easy way to represent and display multi-dimensional
|
14
|
+
arrays in a visually appealing tabular format, making data analysis and debugging
|
15
|
+
more intuitive.
|
16
|
+
email:
|
17
|
+
- vibhatsu.choubey@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/visual_array.rb
|
25
|
+
- lib/visual_array/version.rb
|
26
|
+
- sig/visual_array.rbs
|
27
|
+
homepage: https://github.com/chandu89/visual_array
|
28
|
+
licenses: []
|
29
|
+
metadata:
|
30
|
+
allowed_push_host: https://rubygems.org
|
31
|
+
homepage_uri: https://github.com/chandu89/visual_array
|
32
|
+
source_code_uri: https://github.com/chandu89/visual_array
|
33
|
+
changelog_uri: https://github.com/chandu89/visual_array/blob/main/CHANGELOG.md
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.1.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.4.19
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: A Ruby gem for visualizing multi-dimensional arrays in a structured tabular
|
53
|
+
format.
|
54
|
+
test_files: []
|