NestedStringParser
takes a multi-line string, containing indented lines, and returns a Node
object for each line, such that:
node.parent
returns the node for the most recent less-indented previous linenode.children
returns the nodes for all following more-indented lines, either up to end-of-string, or up to the next equally-indented or less-indented linenode.value
returns the stripped text of the linenode.indent
returns 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.
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
- 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