Class: Stanza

Inherits:
Object
  • Object
show all
Defined in:
lib/AIX/stanza.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Stanza

Returns a new instance of Stanza.



8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/AIX/stanza.rb', line 5

def data
  @data
end

#data_string_rawObject (readonly)

Returns the value of attribute data_string_raw.



6
7
8
# File 'lib/AIX/stanza.rb', line 6

def data_string_raw
  @data_string_raw
end

Instance Method Details

#parse(string) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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