Class: IndentedListParser
- Inherits:
-
Object
- Object
- IndentedListParser
- Defined in:
- lib/indented-list/indented-list-parser.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(list) ⇒ IndentedListParser
constructor
Parses a whitespace indented nested list and returns its content as an object of nested Hashes and Arrays.
Constructor Details
#initialize(list) ⇒ IndentedListParser
Parses a whitespace indented nested list and returns its content as an object of nested Hashes and Arrays.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/indented-list/indented-list-parser.rb', line 7 def initialize( list ) case list when String source = list && File.exist?( list ) ? File.readlines( list ) : list.lines when Array source = list else abort "List can be given as a file name, String or Array. The class of the currently used list '#{list}' is: #{list.class}." end raw = source.map(&:chomp).select { |line| line if !line.match(/^\s*$/) } @list = step raw end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
2 3 4 |
# File 'lib/indented-list/indented-list-parser.rb', line 2 def list @list end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
2 3 4 |
# File 'lib/indented-list/indented-list-parser.rb', line 2 def raw @raw end |