class Stanza

Attributes

data[R]
data_string_raw[R]

Public Class Methods

new(string) click to toggle source
# File lib/AIX/stanza.rb, line 8
def initialize(string)

  @data = Hash.new
  @data_string_raw=''


  if string.length > 0
    @data_string_raw = string
    self.parse(string)
  end
end

Public Instance Methods

parse(string) click to toggle source
# File lib/AIX/stanza.rb, line 20
def parse(string)

  name = nil

  string.split("\n").each { |line|

    if match = /^(\w+):\s*/.match(line)

      name = match[1]
      @data[name] = Hash.new
    elsif match = /^\s+(\w+)\s*=\s*(.*)\s*$/.match(line)
      argument = match[1]
      value = match[2]

      if argument == 'alloc_count'
        @data[name][argument] = value.to_i
      else
        @data[name][argument] = value
      end

    elsif line =~ /^\s*$/
      next
    else
      raise Exception, "wrong string >#{line}<"
    end
  }

  @data
end