https://github.com/a6b8/console-hash-array-for-ruby
Console print progress bar for hash arrays.
https://github.com/a6b8/console-hash-array-for-ruby
development hash print ruby
Last synced: over 1 year ago
JSON representation
Console print progress bar for hash arrays.
- Host: GitHub
- URL: https://github.com/a6b8/console-hash-array-for-ruby
- Owner: a6b8
- License: mit
- Created: 2021-08-20T21:38:03.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-22T00:56:11.000Z (over 4 years ago)
- Last Synced: 2025-02-18T16:08:16.980Z (over 1 year ago)
- Topics: development, hash, print, ruby
- Language: Ruby
- Homepage:
- Size: 85 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Console print progress bar for hash arrays.
**Default output without options**
```ruby
require 'console_hash_array'
groups = ConsoleHashArray.example()
groups.keys.each.with_index do | key, rindex |
ConsoleHashArray.console( groups, rindex, nil, key, :left )
groups[ key ].each.with_index do | item, cindex |
ConsoleHashArray.console( groups, rindex, cindex, key, :right )
end
end
# =>
# [0] Nurwë ..............................
# [1] Legolas ..............................
# [2] Primrose Boffin ..............................
# [3] Aranuir .......
# [4] Ruby Gardner ..............................
# [5] Harding ..............................
# [6] Írimon ..............................
# [7] Torhir Ifant ..............................
# [8] Anairë ..............................
# [9] Golasgil ..............................
# [10] Mîm ..............................
# [11] Tobold Hornblower ..............
# [12] Thrór .....
# [13] Gerda Boffin ..............................
```
**Custom output with options**
```ruby
require 'console_hash_array'
groups = ConsoleHashArray.example()
options = {
right__boxes_total: 10,
style__spaces: '.',
style__steps: '#',
print__left: "{{rindex}}.{{key}}{{left__spaces}}.."
}
groups.keys.each.with_index do | key, rindex |
ConsoleHashArray.console( groups, rindex, nil, key, :left )
groups[ key ].each.with_index do | item, cindex |
ConsoleHashArray.console( groups, rindex, cindex, key, :right, options )
end
end
# =>
# 0. Nurwë ####################
# 1. Legolas ##
# 2. Primrose Boffin #####
# 3. Aranuir ###########
# 4. Ruby Gardner ########
# 5. Harding ##########
# 6. Írimon ####################
# 7. Torhir Ifant ####################
# 8. Anairë ####
# 9. Golasgil ####
# 10. Mîm
# 11. Tobold Hornblower #####
# 12. Thrór ####################
# 13. Gerda Boffin #####
```
1. [Examples](#examples)
1. [Quickstart](#quickstart)
2. [Setup](#setup)
3. [Methods](#methods)
4. [Options](#options)
5. [Contributing](#contributing)
6. [Limitations](#limitations)
7. [License](#license)
8. [Code of Conduct](#code-of-conduct)
9. [Support my Work](#support-my-work)
```ruby
require 'console_hash_array'
groups = ConsoleHashArray.example()
groups.keys.each.with_index do | key, rindex |
ConsoleHashArray.console( groups, rindex, nil, key, :left )
groups[ key ].each.with_index do | item, cindex |
ConsoleHashArray.console( groups, rindex, cindex, key, :right )
end
end
```
Add this line to your application's Gemfile:
```bash
gem console_hash_array
```
And then execute:
```bash
bundle install console_hash_array
```
Or install it yourself as:
```bash
gem install console_hash_array
```
On Rubygems:
- Gem: https://rubygems.org/gems/console_hash_array
- Profile: https://rubygems.org/profiles/a6b8
### .example()
```ruby
require 'console_hash_array'
groups = ConsoleHashArray.example()
```
**Return**
Hash
### .console()
```ruby
require 'console_hash_array'
ConsoleHashArray.console( groups, rindex, cindex, key, :left )
```
**Input**
| | **Type** | **Required** | **Description** |
|------:|:------|:------|:------|
| **groups** | ```Hash of Arrays``` | Yes | Full Groups Hash |
| **rindex** | ```Int``` | Yes | Set row index for calculation and output options. |
| **cindex** | ```Int``` | :left = nil, :right = Yes | Set column index for calculation and output options. |
| **key** | ```String``` or ```Symbol``` | Yes | Set current key from groups hash. |
| **mode** | ```Symbol``` | Yes | Use ```:left``` for initialization row, ```:right``` will update progres line |
| **options** | ```Hash``` | No | Change default behaviour. See options for more informations. |
**Return**
Hash (p)
| Nr | Name | Key | Default | Type | Description |
| :-- | :-- | :-- | :-- | :-- | :-- |
| 1 | Boxes Total | `:right__boxes_total` | `30`| Int | Set length of progres bar |
| 2 | Spaces | `:style__spaces` | `" "`| String | Set Character of space |
| 3 | Steps | `:style__steps` | `"."`| String | Set Character of steps |
| 4 | Print Left | `:print__left` | `"[{{rindex}}] {{key}} {{left__spaces}} "`| String | Set Structure for `:left` |
Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/console-hash-array-for-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/a6b8/console-hash-array-for-ruby/blob/master/CODE_OF_CONDUCT.md).
- Build for development usage
- No input validation
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Everyone interacting in the console-hash-array-for-ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/console-hash-array-for-ruby/blob/master/CODE_OF_CONDUCT.md).
Please ⭐️ star this Project, every ⭐️ star makes us very happy!