class TplinkCli::Iniparse
Public Class Methods
new(string)
click to toggle source
# File lib/tplink-cli/helpers/iniparse.rb, line 3 def initialize(string) @string = string @stack = {} end
parse(string)
click to toggle source
# File lib/tplink-cli/helpers/iniparse.rb, line 19 def self.parse(string) new(string).parse end
Public Instance Methods
parse()
click to toggle source
# File lib/tplink-cli/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
Private Instance Methods
add_key_value(key, value)
click to toggle source
# File lib/tplink-cli/helpers/iniparse.rb, line 30 def add_key_value(key, value) if value.to_s[/^\d+$/] value = value.to_i end @current_item[key] = value end
new_group(group)
click to toggle source
# File lib/tplink-cli/helpers/iniparse.rb, line 25 def new_group(group) @current_item = {} @stack[group] = @current_item end