console_hash_array 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -33
- data/console_hash_array-0.1.0.gem +0 -0
- data/lib/console_hash_array.rb +43 -30
- data/lib/console_hash_array/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17b06d5e106a8b5c94f77587a604da743935843e8dce07fda2b2860134f39564
|
4
|
+
data.tar.gz: 195ea5d0c40ac17bebb8ad678555b68aae272064302f85ac968c1df7cf03b716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a75a7d97d5dad5b491e7eec96a2a1921ea5cc302ac33cbb2de28bb330f6878f506ff13a0069811ed8204ef0038e1119fec2ea170bbe2330df0f77b282cc7761d
|
7
|
+
data.tar.gz: 57ddd01d85e2c8086f6ece2859fed25f4c2d0972e9f0c75568c81976dbc86ad3365807eedb8fa27f46dd1d21bc0b4298c89137634257b2c7a8b28d2378f11952
|
data/README.md
CHANGED
@@ -2,44 +2,45 @@
|
|
2
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
3
|
</a>
|
4
4
|
|
5
|
-
|
5
|
+
Console print progress bar for hash arrays.
|
6
6
|
<br>
|
7
7
|
<br>
|
8
8
|
<br>
|
9
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="
|
10
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/console-hash-array-for-ruby/readme/headlines/examples.svg" height="55px" name="example" alt="Example">
|
11
11
|
</a>
|
12
12
|
<br>
|
13
|
-
|
13
|
+
|
14
14
|
```ruby
|
15
15
|
require 'console_hash_array'
|
16
16
|
|
17
17
|
groups = ConsoleHashArray.example()
|
18
18
|
groups.keys.each.with_index do | key, rindex |
|
19
|
-
|
19
|
+
ConsoleHashArray.console( groups, rindex, nil, key, :left )
|
20
20
|
groups[ key ].each.with_index do | item, cindex |
|
21
|
-
|
21
|
+
ConsoleHashArray.console( groups, rindex, cindex, key, :right )
|
22
22
|
end
|
23
|
-
puts
|
24
23
|
end
|
25
24
|
|
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 ..............................
|
25
|
+
# =>
|
26
|
+
# [0] Nurwë ..............................
|
27
|
+
# [1] Legolas ..............................
|
28
|
+
# [2] Primrose Boffin ..............................
|
29
|
+
# [3] Aranuir .......
|
30
|
+
# [4] Ruby Gardner ..............................
|
31
|
+
# [5] Harding ..............................
|
32
|
+
# [6] Írimon ..............................
|
33
|
+
# [7] Torhir Ifant ..............................
|
34
|
+
# [8] Anairë ..............................
|
35
|
+
# [9] Golasgil ..............................
|
36
|
+
# [10] Mîm ..............................
|
37
|
+
# [11] Tobold Hornblower ..............
|
38
|
+
# [12] Thrór .....
|
39
|
+
# [13] Gerda Boffin ..............................
|
41
40
|
|
42
41
|
```
|
42
|
+
<br>
|
43
|
+
<br>
|
43
44
|
|
44
45
|
<a href="#table-of-contents">
|
45
46
|
<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">
|
@@ -66,11 +67,10 @@ require 'console_hash_array'
|
|
66
67
|
|
67
68
|
groups = ConsoleHashArray.example()
|
68
69
|
groups.keys.each.with_index do | key, rindex |
|
69
|
-
|
70
|
+
ConsoleHashArray.console( groups, rindex, nil, key, :left )
|
70
71
|
groups[ key ].each.with_index do | item, cindex |
|
71
|
-
|
72
|
+
ConsoleHashArray.console( groups, rindex, cindex, key, :right )
|
72
73
|
end
|
73
|
-
puts
|
74
74
|
end
|
75
75
|
```
|
76
76
|
<br>
|
@@ -81,18 +81,19 @@ end
|
|
81
81
|
|
82
82
|
Add this line to your application's Gemfile:
|
83
83
|
|
84
|
-
```
|
85
|
-
gem
|
84
|
+
```bash
|
85
|
+
gem console_hash_array
|
86
86
|
```
|
87
87
|
|
88
88
|
And then execute:
|
89
|
-
|
90
|
-
|
89
|
+
```bash
|
90
|
+
bundle install console_hash_array
|
91
|
+
```
|
91
92
|
|
92
93
|
Or install it yourself as:
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
```bash
|
95
|
+
gem install console_hash_array
|
96
|
+
```
|
96
97
|
|
97
98
|
On Rubygems:
|
98
99
|
- Gem: https://rubygems.org/gems/console_hash_array
|
@@ -118,14 +119,13 @@ Hash
|
|
118
119
|
```ruby
|
119
120
|
require 'console_hash_array'
|
120
121
|
|
121
|
-
|
122
|
+
ConsoleHashArray.console( groups, rindex, cindex, key, :left )
|
122
123
|
```
|
123
124
|
|
124
125
|
|
125
126
|
**Input**
|
126
127
|
| | **Type** | **Required** | **Description** |
|
127
128
|
|------:|:------|:------|:------|
|
128
|
-
| **p** | ```Hash``` | :left = nil, :right = Yes | Parameters for console |
|
129
129
|
| **groups** | ```Hash of Arrays``` | Yes | Full Groups Hash |
|
130
130
|
| **rindex** | ```Int``` | Yes | Set row index for calculation and output options. |
|
131
131
|
| **cindex** | ```Int``` | :left = nil, :right = Yes | Set column index for calculation and output options. |
|
@@ -165,6 +165,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/c
|
|
165
165
|
- No input validation
|
166
166
|
<br>
|
167
167
|
<br>
|
168
|
+
|
168
169
|
<a href="#table-of-contents">
|
169
170
|
<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
171
|
</a>
|
Binary file
|
data/lib/console_hash_array.rb
CHANGED
@@ -5,9 +5,34 @@ require_relative "console_hash_array/version"
|
|
5
5
|
module ConsoleHashArray
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
|
-
|
8
|
+
@TEMPLATE = {
|
9
|
+
print: {
|
10
|
+
left: '[{{rindex}}] {{key}} {{left__spaces}} '
|
11
|
+
},
|
12
|
+
style: {
|
13
|
+
spaces: ' ',
|
14
|
+
steps: '.'
|
15
|
+
},
|
16
|
+
left: {
|
17
|
+
max: nil,
|
18
|
+
spaces: nil
|
19
|
+
},
|
20
|
+
right: {
|
21
|
+
boxes_total: 30,
|
22
|
+
box_current: nil,
|
23
|
+
box: nil,
|
24
|
+
boxes: nil,
|
25
|
+
length_max: nil,
|
26
|
+
mark: nil
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
@p = {}
|
31
|
+
|
32
|
+
def self.console( arr, rindex, cindex, key, mode, options={} )
|
9
33
|
def self.options_insert( p, arr, rindex, cindex, key, mode, options )
|
10
|
-
|
34
|
+
|
35
|
+
if !options .keys.include?( :print__left )
|
11
36
|
options[:print__left] = p[:print][:left]
|
12
37
|
end
|
13
38
|
|
@@ -79,31 +104,10 @@ module ConsoleHashArray
|
|
79
104
|
return [ p, errors ]
|
80
105
|
end
|
81
106
|
|
82
|
-
|
107
|
+
p = {}
|
83
108
|
case mode
|
84
109
|
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
|
-
|
110
|
+
p = Marshal.load( Marshal.dump( @TEMPLATE ) )
|
107
111
|
errors = []
|
108
112
|
messages = []
|
109
113
|
p, errors = self.options_insert( p, arr, rindex, cindex, key, mode, options )
|
@@ -130,13 +134,18 @@ module ConsoleHashArray
|
|
130
134
|
end
|
131
135
|
|
132
136
|
print( p[:print][:left] )
|
137
|
+
|
138
|
+
if arr[ key ].length == 0
|
139
|
+
puts
|
140
|
+
end
|
133
141
|
when :right
|
142
|
+
p = @p
|
134
143
|
if !p[:right][:boxes].find_index( cindex ).nil? and p[:right][:boxes].find_index( cindex ) != p[:right][:box_current]
|
135
144
|
box_new = p[:right][:boxes].find_index( cindex )
|
136
145
|
|
137
146
|
( box_new - p[:right][:box_current] ).times.each do | a |
|
138
147
|
if p[:right][:mark] < p[:right][:boxes_total]
|
139
|
-
|
148
|
+
print( p[:style][:steps] )
|
140
149
|
end
|
141
150
|
p[:right][:mark] = p[:right][:mark] + 1
|
142
151
|
end
|
@@ -144,15 +153,19 @@ module ConsoleHashArray
|
|
144
153
|
p[:right][:box_current] = box_new
|
145
154
|
end
|
146
155
|
|
147
|
-
if cindex == arr[ key ].length-1
|
148
|
-
|
149
|
-
|
150
|
-
|
156
|
+
if cindex == arr[ key ].length-1
|
157
|
+
if p[:right][:mark] != arr[ key ].length-1
|
158
|
+
c = p[:right][:boxes_total] - p[:right][:mark]
|
159
|
+
c > ( arr[ key ].length-1 ) ? c = arr[ key ].length-1 : ''
|
160
|
+
c.times.each do | a |
|
151
161
|
print( p[:style][:steps] )
|
162
|
+
end
|
152
163
|
end
|
164
|
+
puts
|
153
165
|
end
|
154
166
|
else
|
155
167
|
end
|
168
|
+
@p = p
|
156
169
|
|
157
170
|
return p
|
158
171
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_hash_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a6b8
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- bin/console
|
29
29
|
- bin/setup
|
30
|
+
- console_hash_array-0.1.0.gem
|
30
31
|
- console_hash_array.gemspec
|
31
32
|
- lib/console_hash_array.rb
|
32
33
|
- lib/console_hash_array/version.rb
|