Class: Odmget

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Odmget

Returns a new instance of Odmget.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/AIX/odmget.rb', line 8

def initialize(string)

  @data = Array.new
  @data_string_raw=''

  @odm_supported_class = %w(SRCsubsys)

  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/odmget.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/odmget.rb', line 6

def data_string_raw
  @data_string_raw
end

Instance Method Details

#parse(string) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/AIX/odmget.rb', line 21

def parse(string)

  entry = ''
  entry_title = ''

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

    if match = %r{^(\w+):\s*$}.match(line)

      self.parse_entry(entry_title, entry) if entry_title.length > 2 #let's ignore first run


      # let's create new entry

      entry_title = match[1]
      entry = line + "\n"
    else
      entry += line + "\n"
    end

  end

  self.parse_entry(entry_title, entry) if entry_title.length > 2 # last run and exlcude case that file (string) is empty

end

#parse_entry(odm_class, entry) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/AIX/odmget.rb', line 44

def parse_entry(odm_class, entry)

raise "Unsuported ODM class '#{odm_class}'" unless @odm_supported_class.include?(odm_class)

object = case odm_class
           when 'SRCsubsys' then Odmget_SRCsubsys.new(entry)
           else
             raise "Unsuported ODM class '#{odm_class}'<"
         end

@data.push(object)

end