No release in over a year
Usefull helper to build all paths in one hash to local files and folders.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.5.0
 Project Readme
Local Path Builder for Ruby

Usefull helper to build all paths in one hash to local files and folders.


Examples
Table of Contents
  1. Quickstart
  2. Setup
  3. Methods
  4. Tree Structure
  5. Console Output
  6. Contributing
  7. Limitations
  8. License
  9. Code of Conduct
  10. Support my Work

Quickstart
require 'local_path_builder'

struct = LocalPathBuilder.helper()
LocalPathBuilder.generate( struct, :both )

Setup

Add this line to your application's Gemfile:

gem 'local_path_builder'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install local_path_builder

On Rubygems:


Methods

.helper()

require 'local_path_builder'

hash = LocalPathBuilder.helper()
# => { path: 

.generate( struct[:path], key )

require 'local_path_builder'

hash = LocalPathBuilder.generate( 
    path_tree, 
    console_mode,  
    salt 
)

Input

Type Required Description Example Description
path tree Hash Yes please refer path structure Define path structure
console mode Symbol Yes :hash Set console output mode. Use :silent, :hash, :path or :both
salt String No '1624262108' Use salt to create unique filenames.

Return
Hash (See also Console Output)


Tree Structure

A struct input is required to generate all paths. Use the following as reference to design your own tree

Example Tree

{
    root: './',
    name: '1',
    children: {
    entry: {
        name: '0-entry',
        files: {
        tsv: {
            name: 'rest-{{SALT}}.tsv',
        }
        }
    },
    converted: {
        name: '1-converted',
        children: {
            json_folder: {
                name: '0-json',
                files: {
                    json: {
                        name: 'data-{{SALT}}.json',
                    }
                }
            },
            tsv_folder: {
                name: '0-tsv',
                files: {
                    tsv: {
                        name: 'data-{{SALT}}.json',
                    }
                }
            }
        },
        files: {
        json: {
            name: 'data-{{SALT}}.json',
        } 
        }
    }
    }
}

LocalPathBuiler.helper() will give you the same output.


Console Output

The second parameter of the .generate() function expects a symbol. you can choose between :silent, :hash, path and both.

:silent

Console stays silent.

:hash

Console log all variables which are available.

LocalPathBuilder.generate( struct, :hash )

TREE OVERVIEW
    hash[:path][:full]
    ┗━ hash[:path][:children][:entry][:full]
    ┗━ hash[:path][:children][:entry][:files][:tsv][:full]
    ┗━ hash[:path][:children][:converted][:full]
    ┗━ hash[:path][:children][:converted][:files][:json][:full]
        ┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
        ┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
        ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
        ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]

:path

Console log all path which were created.

LocalPathBuilder.generate( struct, :path )

TREE OVERVIEW
    ./1/
        ./1/0-entry/
        ./1/0-entry/rest-1624263104.tsv
        ./1/1-converted/
        ./1/1-converted/data-1624263104.json
            ./1/1-converted/0-json/
            ./1/1-converted/0-json/data-1624263104.json
            ./1/1-converted/0-tsv/
            ./1/1-converted/0-tsv/data-1624263104.json

:both

Console log hash variable and the corresponding file path.

LocalPathBuilder.generate( struct, :both )

TREE OVERVIEW
    hash[:path][:full]
    ./1/
    ┗━ hash[:path][:children][:entry][:full]
        ./1/0-entry/
    ┗━ hash[:path][:children][:entry][:files][:tsv][:full]
        ./1/0-entry/rest-1624263104.tsv
    ┗━ hash[:path][:children][:converted][:full]
        ./1/1-converted/
    ┗━ hash[:path][:children][:converted][:files][:json][:full]
        ./1/1-converted/data-1624263104.json
        ┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
            ./1/1-converted/0-json/
        ┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
            ./1/1-converted/0-json/data-1624263104.json
        ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
            ./1/1-converted/0-tsv/
        ┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]
            ./1/1-converted/0-tsv/data-1624263104.json

Contributing

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.


Limitations
  • Only three levels of folders are supported

Credits
License

The gem is available as open source under the terms of the MIT License.


Code of Conduct

Everyone interacting in the LocalPathBuilder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


Star us

Please ⭐️ star this Project, every ⭐️ star makes us very happy!