Class: Inioperator

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

Instance Method Summary collapse

Constructor Details

#initialize(file, commensign, equalsign) ⇒ Inioperator

Returns a new instance of Inioperator.



2
3
4
5
6
7
8
# File 'lib/inioperator.rb', line 2

def initialize(file, commensign, equalsign)
  @file = file
  @lines = File.readlines(@file)
  @comment = commensign
  @equal = equalsign
  getSections
end

Instance Method Details

#comment(section, key) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/inioperator.rb', line 30

def comment(section, key)
  findsectionRang(section)

  (@range["begin"]..@range["end"]).each do |i|
    if @lines[i].match(/#{key}/) and not @lines[i].match( /^#{@comment}/)  #find key and not begin with comment sign
      @lines[i] = "#{@comment}"+@lines[i]
    end
  end
end

#saveFileObject



40
41
42
43
44
45
46
# File 'lib/inioperator.rb', line 40

def saveFile
  file = File.open(@file, "w")
  @lines.each do |line|
    file.write(line)
  end
  file.close()
end

#setValue(section, key, value) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/inioperator.rb', line 10

def setValue(section, key, value)
  findsectionRang(section)

  (@range["begin"]..@range["end"]).each do |i|
    if @lines[i].match(/#{key}/) and not @lines[i].match( /^#{@comment}/)  #find key and not begin with comment sign
      @lines[i] = key+"#{@equal}"+value+"\n"
    end
  end
end

#uncomment(section, key) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/inioperator.rb', line 20

def uncomment(section, key)
  findsectionRang(section)

  (@range["begin"]..@range["end"]).each do |i|
    if @lines[i].match(/^#{@comment}#{key}/)  #find key with comment sign
      @lines[i] = @lines[i][1..-1]
    end
  end
end