Method: EnvParser.parse

Defined in:
lib/cocos/env.rb

.parse(text) ⇒ Object

use a parser class - why? why not?



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cocos/env.rb', line 44

def self.parse( text )
   h = {}

   lineno = 0   
  text.each_line do |line|
    lineno += 1    ## track line numbers for (parse) error reporting


    line = line.strip   ## check: use strip (or be more strict) - why? why not?

    ## skip empty and comment lines

    next if line.empty? || line.start_with?( '#' )

    if m=LINE_RX.match(line)
      key   = m[:key]
      value = m[:value]
      
      ## todo/check - check/warn about duplicates - why? why not?

      h[key] = value
   else 
      raise ParseError,  "line #{lineno} - unknown line type; cannot parse >#{line}<"
   end
  end
  h
end