class IniParse::Parser

Public Instance Methods

parse() click to toggle source

Parses the source string and returns the resulting data structure.

Returns

IniParse::Document

# 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

Public Class Methods

new(source) click to toggle source

Creates a new Parser instance for parsing string source.

Parameters

source<String>

The source string.

# File lib/iniparse/parser.rb, line 31
def initialize(source)
  @source = source.dup.sub(/\n\z/,'')
end
parse_line(line) click to toggle source

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.

Raises

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
parse_types() click to toggle source

Returns the line types.

Returns

Array

# File lib/iniparse/parser.rb, line 9
def self.parse_types
  @@parse_types ||= []
end
parse_types=(types) click to toggle source