Class: Stanza
- Inherits:
-
Object
- Object
- Stanza
- Defined in:
- lib/AIX/stanza.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_string_raw ⇒ Object
readonly
Returns the value of attribute data_string_raw.
Instance Method Summary collapse
-
#initialize(string) ⇒ Stanza
constructor
A new instance of Stanza.
- #parse(string) ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/AIX/stanza.rb', line 5 def data @data end |
#data_string_raw ⇒ Object (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 |