Class: TplinkAdmin::Iniparse

Inherits:
Object
  • Object
show all
Defined in:
lib/tplink-admin/helpers/iniparse.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Iniparse

Returns a new instance of Iniparse.



3
4
5
6
# File 'lib/tplink-admin/helpers/iniparse.rb', line 3

def initialize(string)
  @string = string
  @stack = {}
end

Class Method Details

.parse(string) ⇒ Object



19
20
21
# File 'lib/tplink-admin/helpers/iniparse.rb', line 19

def self.parse(string)
  new(string).parse
end

Instance Method Details

#parseObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/tplink-admin/helpers/iniparse.rb', line 8

def parse
  @string.split("\n").each do |line|
    case line
    when /^\[/ then new_group(line)
    when /(.*)=(.*)/ then add_key_value($1, $2)
    else raise NotImplementedError.new(line)
    end
  end
  @stack
end