Parses the source string and returns the resulting data structure.
# File lib/iniparse/parser.rb, line 40 def parse IniParse::Generator.gen do |generator| @source.split("\n", -1).each do |line| generator.send(*Parser.parse_line(line)) end end end
Creates a new Parser instance for parsing string
source.
The source string.
# File lib/iniparse/parser.rb, line 31 def initialize(source) @source = source.dup.sub(/\n\z/,'') end
Takes a raw line from an INI document, striping out any inline comment, and indent, then returns the appropriate tuple so that the Generator instance can add the line to the Document.
IniParse::ParseError: If the line could not be parsed.
# File lib/iniparse/parser.rb, line 56 def parse_line(line) sanitized, opts = strip_indent(*strip_comment(line, {})) parsed = nil @@parse_types.each do |type| break if (parsed = type.parse(sanitized, opts)) end if parsed.nil? raise IniParse::ParseError, "A line of your INI document could not be parsed to a " "LineType: '#{line}'." end parsed end
Returns the line types.
Array
# File lib/iniparse/parser.rb, line 9 def self.parse_types @@parse_types ||= [] end
Sets the line types. Handy if you want to add your own custom Line classes.
# File lib/iniparse/parser.rb, line 19 def self.parse_types=(types) parse_types.replace(types) end