Class: IndentedListParser

Inherits:
Object
  • Object
show all
Defined in:
lib/indented-list/indented-list-parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#listObject (readonly)

Returns the value of attribute list.



2
3
4
# File 'lib/indented-list/indented-list-parser.rb', line 2

def list
  @list
end

#rawObject (readonly)

Returns the value of attribute raw.



2
3
4
# File 'lib/indented-list/indented-list-parser.rb', line 2

def raw
  @raw
end