module MgNu::Parser

Public Instance Methods

parse_until(file, regexp, discard = true) click to toggle source

Reads a file until the given regexp is found

@param [File, Regexp, Bool] file object and regular expression to

search for and a boolean indicating whether or not to discard
the regexp line or push it back onto the file

@return [Array] lines from file up to but NOT including the

regexp matchline
# File lib/mgnu/parser.rb, line 33
def parse_until(file, regexp, discard = true)
  buffer = Array.new
  file.each do |line|
    if line =~ regexp and buffer.length != 0
      # found exit condition
      if discard
        file.seek(-line.length, IO::SEEK_CUR) # push this line back on and return
      end
      return buffer
    else
      buffer << line.chomp
    end
  end # end of file.each do |line|
  return buffer
end
strip_quotes(input) click to toggle source

Remove quotes from a string

@param [String] input string to strip @return [String] input string with quotes removed

# File lib/mgnu/parser.rb, line 21
def strip_quotes(input)
  input = Regexp.last_match[1] if input =~ /^["'](.+)["']$/
  input
end