console_hash_array 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +188 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/console_hash_array.gemspec +37 -0
- data/lib/console_hash_array.rb +184 -0
- data/lib/console_hash_array/version.rb +5 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc49e54b0384ab7ea8ab265636b04d6a74bd66d17efb8118c5c862db7068c831
|
4
|
+
data.tar.gz: 4e8776dc9d50d8418e0b0c7fe7c675d6204f2dab2689ed25ad8d24568891eb89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e762a80d5a26a702b787b0c5d5dd4a64df220e400351ee1b7af8e1501e0ba7b4116712b96249b91f1dc9b1a165358d1597424fa2cb384ae63c08fe303c4beeb5
|
7
|
+
data.tar.gz: 1412b4fd09db7c3565ad7974a66fc484f6b66ee8f8940c5a3999aee3615ca5578c10c5689d2578f314237fcda633360612af2aea59aa9f3c000abe65d1f4cc5d
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andreasbanholzer@me.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 a6b8
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
<a href="#table-of-contents">
|
2
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/Headline.svg" height="55px" name="Console Hash Array" alt="# Console Hash Array">
|
3
|
+
</a>
|
4
|
+
|
5
|
+
Helper to print progress bar for hash array with long processes.
|
6
|
+
<br>
|
7
|
+
<br>
|
8
|
+
<br>
|
9
|
+
<a href="#table-of-contents">
|
10
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/examples.svg" height="55px" name="examples" alt="Examples">
|
11
|
+
</a>
|
12
|
+
<br>
|
13
|
+
<br>
|
14
|
+
```ruby
|
15
|
+
require 'console_hash_array'
|
16
|
+
|
17
|
+
groups = ConsoleHashArray.example()
|
18
|
+
groups.keys.each.with_index do | key, rindex |
|
19
|
+
p = ConsoleHashArray.console( nil, groups, rindex, nil, key, :left, {} )
|
20
|
+
groups[ key ].each.with_index do | item, cindex |
|
21
|
+
p = ConsoleHashArray.console( p, groups, rindex, cindex, key, :right, {} )
|
22
|
+
end
|
23
|
+
puts
|
24
|
+
end
|
25
|
+
|
26
|
+
#=>
|
27
|
+
[0] Nurwë ..............................
|
28
|
+
[1] Legolas ..............................
|
29
|
+
[2] Primrose Boffin ..............................
|
30
|
+
[3] Aranuir .......
|
31
|
+
[4] Ruby Gardner ..............................
|
32
|
+
[5] Harding ..............................
|
33
|
+
[6] Írimon ..............................
|
34
|
+
[7] Torhir Ifant ..............................
|
35
|
+
[8] Anairë ..............................
|
36
|
+
[9] Golasgil ..............................
|
37
|
+
[10] Mîm ..............................
|
38
|
+
[11] Tobold Hornblower ..............
|
39
|
+
[12] Thrór .....
|
40
|
+
[13] Gerda Boffin ..............................
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
<a href="#table-of-contents">
|
45
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/table-of-contents.svg" height="55px" name="table-of-contents" alt="Table of Contents">
|
46
|
+
</a>
|
47
|
+
<br>
|
48
|
+
|
49
|
+
1. [Quickstart](#quickstart)<br>
|
50
|
+
2. [Parameters](#parameters)<br>
|
51
|
+
3. [Options](#options)<br>
|
52
|
+
4. [Contributing](#contributing)<br>
|
53
|
+
5. [Limitations](#limitations)<br>
|
54
|
+
6. [License](#license)<br>
|
55
|
+
7. [Code of Conduct](#code-of-conduct)<br>
|
56
|
+
8. [Support my Work](#support-my-work)<br>
|
57
|
+
|
58
|
+
<br>
|
59
|
+
<br>
|
60
|
+
<a href="#table-of-contents">
|
61
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/quickstart.svg" height="55px" name="quickstart" alt="Quickstart">
|
62
|
+
</a>
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'console_hash_array'
|
66
|
+
|
67
|
+
groups = ConsoleHashArray.example()
|
68
|
+
groups.keys.each.with_index do | key, rindex |
|
69
|
+
p = ConsoleHashArray.console( nil, groups, rindex, nil, key, :left, {} )
|
70
|
+
groups[ key ].each.with_index do | item, cindex |
|
71
|
+
p = ConsoleHashArray.console( p, groups, rindex, cindex, key, :right, {} )
|
72
|
+
end
|
73
|
+
puts
|
74
|
+
end
|
75
|
+
```
|
76
|
+
<br>
|
77
|
+
<br>
|
78
|
+
<a href="#table-of-contents">
|
79
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/setup.svg" height="55px" name="setup" alt="Setup">
|
80
|
+
</a>
|
81
|
+
|
82
|
+
Add this line to your application's Gemfile:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
gem 'console_hash_array'
|
86
|
+
```
|
87
|
+
|
88
|
+
And then execute:
|
89
|
+
|
90
|
+
$ bundle install
|
91
|
+
|
92
|
+
Or install it yourself as:
|
93
|
+
|
94
|
+
$ gem install test
|
95
|
+
|
96
|
+
|
97
|
+
On Rubygems:
|
98
|
+
- Gem: https://rubygems.org/gems/console_hash_array
|
99
|
+
- Profile: https://rubygems.org/profiles/a6b8
|
100
|
+
|
101
|
+
<br>
|
102
|
+
<br>
|
103
|
+
<a href="#table-of-contents">
|
104
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/methods.svg" height="55px" name="methods" alt="Methods">
|
105
|
+
</a>
|
106
|
+
|
107
|
+
### .example()
|
108
|
+
```ruby
|
109
|
+
require 'console_hash_array'
|
110
|
+
|
111
|
+
groups = ConsoleHashArray.example()
|
112
|
+
```
|
113
|
+
**Return**<br>
|
114
|
+
Hash
|
115
|
+
|
116
|
+
|
117
|
+
### .console()
|
118
|
+
```ruby
|
119
|
+
require 'console_hash_array'
|
120
|
+
|
121
|
+
p = ConsoleHashArray.console( nil, groups, rindex, cindex, key, :left, {} )
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
**Input**
|
126
|
+
| | **Type** | **Required** | **Description** |
|
127
|
+
|------:|:------|:------|:------|
|
128
|
+
| **p** | ```Hash``` | :left = nil, :right = Yes | Parameters for console |
|
129
|
+
| **groups** | ```Hash of Arrays``` | Yes | Full Groups Hash |
|
130
|
+
| **rindex** | ```Int``` | Yes | Set row index for calculation and output options. |
|
131
|
+
| **cindex** | ```Int``` | :left = nil, :right = Yes | Set column index for calculation and output options. |
|
132
|
+
| **key** | ```String``` or ```Symbol``` | Yes | Set current key from groups hash. |
|
133
|
+
| **mode** | ```Symbol``` | Yes | Use ```:left``` for initialization row, ```:right``` will update progres line |
|
134
|
+
| **options** | ```Hash``` | No | Change default behaviour. See options for more informations. |
|
135
|
+
|
136
|
+
**Return**<br>
|
137
|
+
Hash (p)
|
138
|
+
<br>
|
139
|
+
<br>
|
140
|
+
<br>
|
141
|
+
<a href="#table-of-contents">
|
142
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/options.svg" height="55px" name="options" alt="Options">
|
143
|
+
</a>
|
144
|
+
| Nr | Name | Key | Default | Type | Description |
|
145
|
+
| :-- | :-- | :-- | :-- | :-- | :-- |
|
146
|
+
| 1 | Boxes Total | `:right__boxes_total` | `30`| Int | Set length of progres bar |
|
147
|
+
| 2 | Spaces | `:style__spaces` | `" "`| String | Set Character of space |
|
148
|
+
| 3 | Steps | `:style__steps` | `"."`| String | Set Character of steps |
|
149
|
+
| 4 | Print Left | `:print__left` | `"[{{rindex}}] {{key}} {{left__spaces}} "`| String | Set Structure for `:left` |
|
150
|
+
|
151
|
+
<br>
|
152
|
+
<br>
|
153
|
+
<a href="#table-of-contents">
|
154
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/contributing.svg" height="55px" name="contributing" alt="Contributing">
|
155
|
+
</a>
|
156
|
+
|
157
|
+
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).
|
158
|
+
<br>
|
159
|
+
<br>
|
160
|
+
<br>
|
161
|
+
<a href="#table-of-contents">
|
162
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/limitations.svg" height="55px" name="limitations" alt="Limitations">
|
163
|
+
</a>
|
164
|
+
- Build for development usage
|
165
|
+
- No input validation
|
166
|
+
<br>
|
167
|
+
<br>
|
168
|
+
<a href="#table-of-contents">
|
169
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/license.svg" height="55px" name="license" alt="License">
|
170
|
+
</a>
|
171
|
+
|
172
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
173
|
+
<br>
|
174
|
+
<br>
|
175
|
+
<br>
|
176
|
+
<a href="#table-of-contents">
|
177
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/code-of-conduct.svg" height="55px" name="code-of-conduct" alt="Code of Conduct">
|
178
|
+
</a>
|
179
|
+
|
180
|
+
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).
|
181
|
+
<br>
|
182
|
+
<br>
|
183
|
+
<br>
|
184
|
+
<a href="#table-of-contents">
|
185
|
+
<img href="#table-of-contents" src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/support-my-work.svg" height="55px" name="support-my-work" alt="Support my Work">
|
186
|
+
</a>
|
187
|
+
|
188
|
+
Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "console_hash_array"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/console_hash_array/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "console_hash_array"
|
7
|
+
spec.version = ConsoleHashArray::VERSION
|
8
|
+
spec.authors = ["a6b8"]
|
9
|
+
spec.email = ["hello@13plus4.com"]
|
10
|
+
|
11
|
+
spec.summary = "Console print progress bar for hash arrays."
|
12
|
+
spec.description = "Console print progress bar for hash arrays for long processes."
|
13
|
+
spec.homepage = "https://github.com/a6b8/console-hash-array-for-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/a6b8/console-hash-array-for-ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://raw.githubusercontent.com/a6b8/console-hash-array-for-ruby/main/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "console_hash_array/version"
|
4
|
+
|
5
|
+
module ConsoleHashArray
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
def self.console( p, arr, rindex, cindex, key, mode, options={} )
|
9
|
+
def self.options_insert( p, arr, rindex, cindex, key, mode, options )
|
10
|
+
if !options.keys.include?( :print__left )
|
11
|
+
options[:print__left] = p[:print][:left]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
errors = []
|
16
|
+
options.keys.each do | key |
|
17
|
+
allow = [
|
18
|
+
:right__boxes_total,
|
19
|
+
:style__spaces,
|
20
|
+
:style__steps
|
21
|
+
]
|
22
|
+
|
23
|
+
denied = [
|
24
|
+
:print__left
|
25
|
+
]
|
26
|
+
|
27
|
+
if allow.include?( key )
|
28
|
+
kk = key.to_s.split( '__' ).map { | a | a.to_sym }
|
29
|
+
p[ kk[ 0 ] ][ kk[ 1 ] ] = options[ key ]
|
30
|
+
else
|
31
|
+
if !denied.include?( key )
|
32
|
+
error = " \":#{key.to_s}\" - Key not found."
|
33
|
+
errors.push( error )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return [ p, errors ]
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def self. options_print_left( p, arr, rindex, cindex, key, mode, options )
|
42
|
+
errors = []
|
43
|
+
|
44
|
+
if options.keys.include?( :print__left )
|
45
|
+
vars = options[:print__left]
|
46
|
+
.scan( /\{{[a-z,_,:]+\}}/ )
|
47
|
+
.map { | a | a.gsub( /[{:}]/, '' ) }
|
48
|
+
|
49
|
+
str = options[:print__left]
|
50
|
+
vars.each do | var |
|
51
|
+
var = "{{#{var}}}"
|
52
|
+
if !var.index( '__' ).nil?
|
53
|
+
keys = var.split( '__' )
|
54
|
+
.map { | a | a.gsub( /[{}]/, '' ) }
|
55
|
+
.map { | a | a.to_sym }
|
56
|
+
|
57
|
+
str = str.gsub( var, p[ keys[ 0 ] ][ keys[ 1 ] ] )
|
58
|
+
else
|
59
|
+
case var
|
60
|
+
when '{{rindex}}'
|
61
|
+
m = ( arr.keys.length-1 ).to_s.length
|
62
|
+
mm = m - rindex.to_s.length
|
63
|
+
p[:left][:spaces] << mm.times.map { | a | p[:style][:spaces] }.join( '' )
|
64
|
+
str = str.gsub( var, rindex.to_s )
|
65
|
+
when '{{cindex}}'
|
66
|
+
str = str.gsub( var, cindex.to_s )
|
67
|
+
when '{{key}}'
|
68
|
+
str = str.gsub( var, key.to_s )
|
69
|
+
when '{{mode}}'
|
70
|
+
str = str.gsub( var, mode.to_s )
|
71
|
+
else
|
72
|
+
error = " \"#{var}\" - Variable not found."
|
73
|
+
errors.push( error )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
p[:print][:left] = str
|
79
|
+
return [ p, errors ]
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
case mode
|
84
|
+
when :left
|
85
|
+
p = {
|
86
|
+
print: {
|
87
|
+
left: '[{{rindex}}] {{key}} {{left__spaces}} '
|
88
|
+
},
|
89
|
+
style: {
|
90
|
+
spaces: ' ',
|
91
|
+
steps: '.'
|
92
|
+
},
|
93
|
+
left: {
|
94
|
+
max: nil,
|
95
|
+
spaces: nil
|
96
|
+
},
|
97
|
+
right: {
|
98
|
+
boxes_total: 30,
|
99
|
+
box_current: nil,
|
100
|
+
box: nil,
|
101
|
+
boxes: nil,
|
102
|
+
length_max: nil,
|
103
|
+
mark: nil
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
errors = []
|
108
|
+
messages = []
|
109
|
+
p, errors = self.options_insert( p, arr, rindex, cindex, key, mode, options )
|
110
|
+
messages.concat( errors )
|
111
|
+
|
112
|
+
p[:left][:max] = arr.keys.map { | aa | aa.length }.max
|
113
|
+
p[:left][:spaces] = ( p[:left][:max] - key.length ).times.map { | a | p[:style][:spaces] }.join( '' )
|
114
|
+
|
115
|
+
p[:right][:box_current] = 0
|
116
|
+
p[:right][:mark] = 0
|
117
|
+
p[:right][:length_max] = arr[ key ].length
|
118
|
+
p[:right][:box] = p[:right][:length_max] / p[:right][:boxes_total]
|
119
|
+
p[:right][:boxes] = ( 1..p[:right][:boxes_total] ).map { | a | p[:right][:box] * a }
|
120
|
+
|
121
|
+
p, errors = self.options_print_left( p, arr, rindex, cindex, key, mode, options )
|
122
|
+
messages.concat( errors )
|
123
|
+
|
124
|
+
if messages.length != 0 and rindex == 0
|
125
|
+
puts 'Following errors occured:'
|
126
|
+
messages.each do | message |
|
127
|
+
puts message
|
128
|
+
end
|
129
|
+
puts
|
130
|
+
end
|
131
|
+
|
132
|
+
print( p[:print][:left] )
|
133
|
+
when :right
|
134
|
+
if !p[:right][:boxes].find_index( cindex ).nil? and p[:right][:boxes].find_index( cindex ) != p[:right][:box_current]
|
135
|
+
box_new = p[:right][:boxes].find_index( cindex )
|
136
|
+
|
137
|
+
( box_new - p[:right][:box_current] ).times.each do | a |
|
138
|
+
if p[:right][:mark] < p[:right][:boxes_total]
|
139
|
+
print( p[:style][:steps] )
|
140
|
+
end
|
141
|
+
p[:right][:mark] = p[:right][:mark] + 1
|
142
|
+
end
|
143
|
+
|
144
|
+
p[:right][:box_current] = box_new
|
145
|
+
end
|
146
|
+
|
147
|
+
if cindex == arr[ key ].length-1 and p[:right][:mark] != arr[ key ].length-1
|
148
|
+
c = p[:right][:boxes_total] - p[:right][:mark]
|
149
|
+
c > ( arr[ key ].length-1 ) ? c = arr[ key ].length-1 : ''
|
150
|
+
c.times.each do | a |
|
151
|
+
print( p[:style][:steps] )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
else
|
155
|
+
end
|
156
|
+
|
157
|
+
return p
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def self.example()
|
162
|
+
groups = {}
|
163
|
+
examples = [
|
164
|
+
'Nurwë',
|
165
|
+
'Legolas',
|
166
|
+
'Primrose Boffin',
|
167
|
+
'Aranuir',
|
168
|
+
'Ruby Gardner',
|
169
|
+
'Harding',
|
170
|
+
'Írimon',
|
171
|
+
'Torhir Ifant',
|
172
|
+
'Anairë',
|
173
|
+
'Golasgil',
|
174
|
+
'Mîm',
|
175
|
+
'Tobold Hornblower',
|
176
|
+
'Thrór',
|
177
|
+
'Gerda Boffin'
|
178
|
+
]
|
179
|
+
examples.each { | key | groups[ key ] =
|
180
|
+
rand( 0..rand( 0..100 ) ).times.map { | a | rand( 0..100 ) } }
|
181
|
+
|
182
|
+
return groups
|
183
|
+
end
|
184
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console_hash_array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- a6b8
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Console print progress bar for hash arrays for long processes.
|
14
|
+
email:
|
15
|
+
- hello@13plus4.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- console_hash_array.gemspec
|
31
|
+
- lib/console_hash_array.rb
|
32
|
+
- lib/console_hash_array/version.rb
|
33
|
+
homepage: https://github.com/a6b8/console-hash-array-for-ruby
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
allowed_push_host: https://rubygems.org
|
38
|
+
homepage_uri: https://github.com/a6b8/console-hash-array-for-ruby
|
39
|
+
source_code_uri: https://github.com/a6b8/console-hash-array-for-ruby
|
40
|
+
changelog_uri: https://raw.githubusercontent.com/a6b8/console-hash-array-for-ruby/main/CHANGELOG.md
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.4.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.2.3
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Console print progress bar for hash arrays.
|
60
|
+
test_files: []
|