NestedStringParser
NestedStringParser takes a multi-line string, containing indented lines, and returns a Node object for each line, such that:
-
node.parentreturns the node for the most recent less-indented previous line -
node.childrenreturns the nodes for all following more-indented lines, either up to end-of-string, or up to the next equally-indented or less-indented line -
node.valuereturns the stripped text of the line -
node.indentreturns the length of the blank string for this line in the source string
See specs for some examples.
NestedStringParser is not terribly fussy about indentation ; any string that is indented more than a previous string will be assigned the previous string as parent. Use format to normalise indentation if your input is sloppy. Specs provide an example of sloppy indentation.
Installation
Add this line to your application's Gemfile:
gem 'nested_string_parser'And then execute:
$ bundle
Or install it yourself as:
$ gem install nested_string_parser
Contributing
- Fork it ( https://github.com/[my-github-username]/nested_string_parser/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request