local_path_builder 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c3840528ff167321fcf9505c37d5fd67b018d778807676a3bc40c4a3642931ee
4
+ data.tar.gz: 89574474708e933c497ca7402ebd2ac4c31c10aea80cd69573b0a30404cb24c8
5
+ SHA512:
6
+ metadata.gz: 3b3b9aa2caa57b218c8da11d4a64c9e8b874b82d11b01f836bbbd7ee9a7bcec5d4225ad3a03176ca8d686ccebc5b16d1c5059c3ff1fc169bdbbb5094bdf91a5f
7
+ data.tar.gz: 200de47f2b2ed1cdf37d023af4fcd2f75bb4c36871f04c76ac37b320286e258bdc80ccbd0815108091915de417159d65f7e3d7989460c135149d555612864b5a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-06-20
4
+
5
+ - Initial release
@@ -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 hello@13plus4.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
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in local_path_builder.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
11
+
12
+ gem 'fileutils', "~> 1.5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ local_path_builder (0.1.0)
5
+ fileutils (~> 1.5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ fileutils (1.5.0)
12
+ parallel (1.20.1)
13
+ parser (3.0.1.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (13.0.3)
17
+ regexp_parser (2.1.1)
18
+ rexml (3.2.5)
19
+ rubocop (1.17.0)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.0.0.0)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
+ rexml
25
+ rubocop-ast (>= 1.7.0, < 2.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.7.0)
29
+ parser (>= 3.0.1.1)
30
+ ruby-progressbar (1.11.0)
31
+ unicode-display_width (2.0.0)
32
+
33
+ PLATFORMS
34
+ x86_64-darwin-20
35
+
36
+ DEPENDENCIES
37
+ fileutils (~> 1.5.0)
38
+ local_path_builder!
39
+ rake (~> 13.0)
40
+ rubocop (~> 1.7)
41
+
42
+ BUNDLED WITH
43
+ 2.2.19
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,265 @@
1
+ <a href="#table-of-contents">
2
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/local-path-builder.svg" height="55px" name="local-path-builder" alt="# Local Path Builder for Ruby">
3
+ </a>
4
+
5
+ Usefull helper to build all paths in one hash to local files and folders.
6
+ <br>
7
+ <br>
8
+ <br>
9
+ <a href="#table-of-contents">
10
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/table-of-contents.svg" height="55px" name="table-of-contents" alt="Table of Contents">
11
+ </a>
12
+ <br>
13
+
14
+ 1. [Quickstart](#quickstart)<br>
15
+ 2. [Setup](#setup)<br>
16
+ 3. [Methods](#methods)<br>
17
+ 4. [Tree Structure](#tree-structure)<br>
18
+ 5. [Console](#console)<br>
19
+ 6. [Contributing](#contributing)<br>
20
+ 7. [Limitations](#limitations)<br>
21
+ 8. [License](#license)<br>
22
+ 9. [Code of Conduct](#code-of-conduct)<br>
23
+ 10. [Support my Work](#support-my-work)<br>
24
+
25
+ <br>
26
+ <br>
27
+ <a href="#table-of-contents">
28
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/quickstart.svg" height="55px" name="quickstart" alt="Quickstart">
29
+ </a>
30
+
31
+ ```ruby
32
+ require '../lib/local_path_builder'
33
+
34
+ struct = LocalPathBuilder.helper()
35
+ LocalPathBuilder.generate( struct, :both )
36
+ ```
37
+ <br>
38
+ <br>
39
+ <a href="#table-of-contents">
40
+ <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">
41
+ </a>
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem 'local_path_builder'
47
+ ```
48
+
49
+ And then execute:
50
+
51
+ $ bundle install
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install local_path_builder
56
+
57
+
58
+ On Rubygems:
59
+ - Gem: https://rubygems.org/gems/local_path_builder
60
+ - Profile: https://rubygems.org/profiles/a6b8
61
+
62
+
63
+ <br>
64
+ <br>
65
+ <a href="#table-of-contents">
66
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/methods.svg" height="55px" name="methods" alt="Methods">
67
+ </a>
68
+
69
+ ### .helper()
70
+
71
+ ```ruby
72
+ hash = LocalPathBuilder.helper()
73
+ # => { path:
74
+ ```
75
+
76
+ ### .generate( struct[:path], key )
77
+
78
+ ```ruby
79
+ require 'local_path_builder'
80
+
81
+ hash = LocalPathBuilder.generate(
82
+ path_tree,
83
+ console_mode,
84
+ salt
85
+ )
86
+ ```
87
+
88
+ **Input**
89
+ | **Type** | **Required** | **Description** | **Example** | **Description** |
90
+ |------:|:------|:------|:------|:------|
91
+ | **path tree** | ```Hash``` | Yes | please refer `path structure` | Define path structure |
92
+ | **console mode** | ```Symbol``` | Yes | ```:hash``` | Set console output mode. Use ```:silent```, ```:hash```, ```:path``` or ```:both``` |
93
+ | **salt** | ```String``` | No | ```'1624262108'``` | Use salt to create unique filenames. |
94
+
95
+ **Return**<br>
96
+ Hash (See also Console Output)
97
+ <br>
98
+ <br>
99
+ <br>
100
+ <a href="#table-of-contents">
101
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/tree-structure.svg" height="55px" name="tree-structure" alt="Tree Structure">
102
+ </a>
103
+
104
+ A struct input is required to generate all paths. Use the following as reference to design your own tree
105
+
106
+ **Example Tree**
107
+
108
+ ```ruby
109
+ {
110
+ root: './',
111
+ name: '1',
112
+ children: {
113
+ entry: {
114
+ name: '0-entry',
115
+ files: {
116
+ tsv: {
117
+ name: 'rest-{{SALT}}.tsv',
118
+ }
119
+ }
120
+ },
121
+ converted: {
122
+ name: '1-converted',
123
+ children: {
124
+ json_folder: {
125
+ name: '0-json',
126
+ files: {
127
+ json: {
128
+ name: 'data-{{SALT}}.json',
129
+ }
130
+ }
131
+ },
132
+ tsv_folder: {
133
+ name: '0-tsv',
134
+ files: {
135
+ tsv: {
136
+ name: 'data-{{SALT}}.json',
137
+ }
138
+ }
139
+ }
140
+ },
141
+ files: {
142
+ json: {
143
+ name: 'data-{{SALT}}.json',
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ ```
150
+ ```LocalPathBuiler.helper()``` will give you the same output.
151
+
152
+ <br>
153
+ <br>
154
+ <a href="#table-of-contents">
155
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/console.svg" height="55px" name="console" alt="Console Output">
156
+ </a>
157
+
158
+ The second parameter of the ```.generate()``` function expects a symbol. you can choose between ```:silent```, ```:hash```, ```path``` and ```both```.
159
+
160
+ ### :silent
161
+ Console stays silent.
162
+
163
+ ### :hash
164
+ Console log all variables which are available.
165
+
166
+ ```txt
167
+ LocalPathBuilder.generate( struct, :hash )
168
+
169
+ TREE OVERVIEW
170
+ hash[:path][:full]
171
+ ┗━ hash[:path][:children][:entry][:full]
172
+ ┗━ hash[:path][:children][:entry][:files][:tsv][:full]
173
+ ┗━ hash[:path][:children][:converted][:full]
174
+ ┗━ hash[:path][:children][:converted][:files][:json][:full]
175
+ ┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
176
+ ┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
177
+ ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
178
+ ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]
179
+ ```
180
+
181
+
182
+ ### :path
183
+ Console log all path which were created.
184
+
185
+ ```txt
186
+ LocalPathBuilder.generate( struct, :path )
187
+
188
+ TREE OVERVIEW
189
+ ./1/
190
+ ./1/0-entry/
191
+ ./1/0-entry/rest-1624263104.tsv
192
+ ./1/1-converted/
193
+ ./1/1-converted/data-1624263104.json
194
+ ./1/1-converted/0-json/
195
+ ./1/1-converted/0-json/data-1624263104.json
196
+ ./1/1-converted/0-tsv/
197
+ ./1/1-converted/0-tsv/data-1624263104.json
198
+ ```
199
+
200
+
201
+ ### :both
202
+ Console log hash variable and the corresponding file path.
203
+
204
+ ```txt
205
+ LocalPathBuilder.generate( struct, :both )
206
+
207
+ TREE OVERVIEW
208
+ hash[:path][:full]
209
+ ./1/
210
+ ┗━ hash[:path][:children][:entry][:full]
211
+ ./1/0-entry/
212
+ ┗━ hash[:path][:children][:entry][:files][:tsv][:full]
213
+ ./1/0-entry/rest-1624263104.tsv
214
+ ┗━ hash[:path][:children][:converted][:full]
215
+ ./1/1-converted/
216
+ ┗━ hash[:path][:children][:converted][:files][:json][:full]
217
+ ./1/1-converted/data-1624263104.json
218
+ ┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
219
+ ./1/1-converted/0-json/
220
+ ┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
221
+ ./1/1-converted/0-json/data-1624263104.json
222
+ ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
223
+ ./1/1-converted/0-tsv/
224
+ ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]
225
+ ./1/1-converted/0-tsv/data-1624263104.json
226
+ ```
227
+
228
+ <br>
229
+ <br>
230
+ <a href="#table-of-contents">
231
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/contributing.svg" height="55px" name="contributing" alt="Contributing">
232
+ </a>
233
+
234
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/statosio-for-wordpress. 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/statosio/blob/master/CODE_OF_CONDUCT.md).
235
+ <br>
236
+ <br>
237
+ <br>
238
+ <a href="#table-of-contents">
239
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/limitations.svg" height="55px" name="limitations" alt="Limitations">
240
+ </a>
241
+ - Only three levels of folders are supported
242
+
243
+ <br>
244
+ <br>
245
+ <a href="#table-of-contents">
246
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/license.svg" height="55px" name="license" alt="License">
247
+ </a>
248
+
249
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
250
+ <br>
251
+ <br>
252
+ <br>
253
+ <a href="#table-of-contents">
254
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/code-of-conduct.svg" height="55px" name="code-of-conduct" alt="Code of Conduct">
255
+ </a>
256
+
257
+ Everyone interacting in the LocalPathBuilder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/local-path-builder-for-ruby/blob/master/CODE_OF_CONDUCT.md).
258
+ <br>
259
+ <br>
260
+ <br>
261
+ <a href="#table-of-contents">
262
+ <img href="#table-of-contents" src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/support-my-work.svg" height="55px" name="support-my-work" alt="Support my Work">
263
+ </a>
264
+
265
+ Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
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 "local_path_builder"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,208 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "local_path_builder/version"
4
+ require 'FileUtils'
5
+
6
+
7
+ module LocalPathBuilder
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+
11
+ def self.helper()
12
+ result = {
13
+ root: './',
14
+ name: '1',
15
+ full: nil,
16
+ children: {
17
+ entry: {
18
+ name: '0-entry',
19
+ full: nil,
20
+ files: {
21
+ tsv: {
22
+ name: 'rest-{{SALT}}.tsv',
23
+ full: nil
24
+ }
25
+ }
26
+ },
27
+ converted: {
28
+ name: '1-converted',
29
+ full: nil,
30
+ children: {
31
+ json_folder: {
32
+ name: '0-json',
33
+ full: nil,
34
+ files: {
35
+ json: {
36
+ name: 'data-{{SALT}}.json',
37
+ full: nil
38
+ }
39
+ }
40
+ },
41
+ tsv_folder: {
42
+ name: '0-tsv',
43
+ full: nil,
44
+ files: {
45
+ tsv: {
46
+ name: 'data-{{SALT}}.json',
47
+ full: nil
48
+ }
49
+ }
50
+ }
51
+ },
52
+ files: {
53
+ json: {
54
+ name: 'data-{{SALT}}.json',
55
+ full: nil
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return result
62
+ end
63
+
64
+
65
+ def self.generate( obj, status, salt=Time.now.getutc.to_i.to_s )
66
+ mode = {
67
+ general: nil,
68
+ hash: nil,
69
+ path: nil
70
+ }
71
+
72
+ case status
73
+ when :silent
74
+ mode[:general] = false
75
+ mode[:hash] = false
76
+ mode[:path] = false
77
+ when :hash
78
+ mode[:general] = true
79
+ mode[:hash] = true
80
+ mode[:path] = false
81
+ when :path
82
+ mode[:general] = true
83
+ mode[:hash] = false
84
+ mode[:path] = true
85
+ when :both
86
+ mode[:general] = true
87
+ mode[:hash] = true
88
+ mode[:path] = true
89
+ end
90
+
91
+
92
+ mode[:general] ? puts( 'TREE OVERVIEW' ) : ''
93
+
94
+ obj[:full] = ''
95
+ obj[:full] += obj[:root]
96
+ obj[:full] += self.helper_parse_path( self.helper_insert_salt( salt, obj[:name] ) )
97
+
98
+ mode[:hash] ? puts( self.helper_obj_path( 'l1', salt, [ ] ) ) : ''
99
+ mode[:path] ? puts( self.draw_obj_path_local( obj[:full], 2, 4 ) ) : ''
100
+
101
+ obj[:children].keys.each { | l2 |
102
+ obj[:children][ l2 ][:full] = ''
103
+ obj[:children][ l2 ][:full] += obj[:full]
104
+ obj[:children][ l2 ][:full] += self.helper_parse_path( self.helper_insert_salt( salt, obj[:children][ l2 ][:name] ) )
105
+ mode[:hash] ? puts( self.helper_obj_path( 'l2', salt, [ l2 ] ) ) : ''
106
+ mode[:path] ? puts( self.draw_obj_path_local( obj[:children][ l2 ][:full], 3, 4 ) ) : ''
107
+ FileUtils.mkdir_p obj[:children][ l2 ][:full]
108
+
109
+ if !obj[:children][ l2 ][:files].nil?
110
+ obj[:children][ l2 ][:files].keys.each { | f1 |
111
+ obj[:children][ l2 ][:files][ f1 ][:full] = ''
112
+ obj[:children][ l2 ][:files][ f1 ][:full] += obj[:children][ l2 ][:full]
113
+ obj[:children][ l2 ][:files][ f1 ][:full] += self.helper_insert_salt( salt, obj[:children][ l2 ][:files][ f1 ][:name] )
114
+ mode[:hash] ? puts( self.helper_obj_path( 'l2', salt, [ l2 ], f1 ) ) : ''
115
+ mode[:path] ? puts( self.draw_obj_path_local( obj[:children][ l2 ][:files][ f1 ][:full], 3, 4 ) ) : ''
116
+ }
117
+ end
118
+
119
+ if !obj[:children][ l2 ][:children].nil?
120
+ obj[:children][ l2 ][:children].keys.each { | l3 |
121
+ obj[:children][ l2 ][:children][ l3 ][:full] = ''
122
+ obj[:children][ l2 ][:children][ l3 ][:full] += obj[:children][ l2 ][:full]
123
+ obj[:children][ l2 ][:children][ l3 ][:full] += self.helper_parse_path( self.helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:name] ) )
124
+
125
+ FileUtils.mkdir_p obj[:children][ l2 ][:children][ l3 ][:full]
126
+ mode[:hash] ? puts( self.helper_obj_path( 'l3', salt, [ l2, l3 ] ) ) : ''
127
+ mode[:path] ? puts( self.draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:full], 4, 4 ) ) : ''
128
+
129
+ if !obj[:children][ l2 ][:children][ l3 ][:files].nil?
130
+ obj[:children][ l2 ][:children][ l3 ][:files].keys.each { | f2 |
131
+ obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] = ''
132
+ obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += obj[:children][ l2 ][:children][ l3 ][:full]
133
+ obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += self.helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:name] )
134
+ mode[:hash] ? puts( self.helper_obj_path( 'l3', salt, [ l2, l3 ], f2 ) ) : ''
135
+ mode[:path] ? puts( self.draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full], 4, 4 ) ) : ''
136
+ }
137
+ end
138
+ }
139
+ end
140
+ }
141
+ return obj
142
+ end
143
+
144
+
145
+ private
146
+
147
+ def self.helper_parse_path( str )
148
+ if str[ str.length - 1, 1 ] != '/'
149
+ str = str + '/'
150
+ end
151
+ return str
152
+ end
153
+
154
+ def self.draw_obj_line_edge( l, offset )
155
+ str = ''
156
+ for i in 1..( ( l - 1 ) * offset )
157
+ str += ' '
158
+ end
159
+ if l > 1
160
+ str += "┗"
161
+ str += "━"
162
+ str += " "
163
+ else
164
+ str += ' '
165
+ end
166
+ return str
167
+ end
168
+
169
+ def self.draw_obj_path_local( str, l, offset )
170
+ result = ''
171
+ for i in 0..( ( l - 1 ) * offset )
172
+ result += ' '
173
+ end
174
+ result += ''
175
+ result += str
176
+ return result
177
+ end
178
+
179
+ def self.helper_obj_path( name, salt, k, f=nil )
180
+ str = ''
181
+ str += self.draw_obj_line_edge( name[ 1, name.length ].to_i, 4 )
182
+ str += 'hash[:path]'
183
+ if k.length == 0
184
+
185
+ else
186
+ for i in 0..k.length-1
187
+ str += '[:children]'
188
+ str += '[:'
189
+ str += k[ i ].to_s
190
+ str += ']'
191
+ end
192
+ end
193
+
194
+ if !f.nil?
195
+ str += '[:files][:'
196
+ str += f.to_s
197
+ str += '][:full]'
198
+ else
199
+ str += '[:full]'
200
+ end
201
+ return str
202
+ end
203
+
204
+ def self.helper_insert_salt( salt, str )
205
+ str = str.gsub( "{{SALT}}", salt )
206
+ return str
207
+ end
208
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocalPathBuilder
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/local_path_builder/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "local_path_builder"
7
+ spec.version = LocalPathBuilder::VERSION
8
+ spec.authors = ["a6b8"]
9
+ spec.email = ["hello@13plu4.com"]
10
+
11
+ spec.summary = "Build all paths in one hash to local files and folders."
12
+ spec.description = "Usefull helper to build all paths in one hash to local files and folders."
13
+ spec.homepage = "https://github.com/a6b8/local-path-builder-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/local-path-builder-for-ruby"
21
+ spec.metadata["changelog_uri"] = "https://raw.githubusercontent.com/a6b8/local-path-builder-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 "fileutils", "~> 1.5.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
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: local_path_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - a6b8
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fileutils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
27
+ description: Usefull helper to build all paths in one hash to local files and folders.
28
+ email:
29
+ - hello@13plu4.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/local_path_builder.rb
46
+ - lib/local_path_builder/version.rb
47
+ - local_path_builder.gemspec
48
+ homepage: https://github.com/a6b8/local-path-builder-for-ruby
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org
53
+ homepage_uri: https://github.com/a6b8/local-path-builder-for-ruby
54
+ source_code_uri: https://github.com/a6b8/local-path-builder-for-ruby
55
+ changelog_uri: https://raw.githubusercontent.com/a6b8/local-path-builder-for-ruby/main/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.4.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.2.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Build all paths in one hash to local files and folders.
75
+ test_files: []