Created
April 22, 2012 15:48
-
-
Save ffaerber/2464782 to your computer and use it in GitHub Desktop.
filelist to hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "awesome_print" | |
| require 'json' | |
| list = [ | |
| "compass-config.rb", | |
| "config.yaml", | |
| "content/00_home/00_index.md", | |
| "content/00_home/01_work.md", | |
| "content/01_additional services/00_index.md", | |
| "content/01_additional services/01_writing labs.md", | |
| "content/01_additional services/02_overview.md", | |
| "content/01_additional services/03_conversation and presentation.md", | |
| "content/01_additional services/04_how can we help you.md", | |
| "content/01_writing services/00_index.md", | |
| "content/01_writing services/01_copy editing.md", | |
| "content/01_writing services/02_3-step process.md", | |
| "content/01_writing services/02_overview.md", | |
| "content/01_writing services/03_overview.md", | |
| "content/01_writing services/03_translations.md", | |
| "content/02_additional services/00_index.md", | |
| ] | |
| list_hash = list.each { |f| | |
| }.map{ |path| | |
| path.split '/' # split to parts | |
| }.inject({}){ |acc, path| # start with empty hash | |
| path.inject(acc) do |acc2, dir| # for each path part, create a child of current node | |
| acc2[dir] ||= {} # and pass it as new current node | |
| end | |
| acc | |
| } | |
| list_json = list_hash.to_json | |
| puts list_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment