Class: Linux::Lxc::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/linux/lxc/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lxc, key, value) ⇒ Line

Returns a new instance of Line.



6
7
8
9
10
11
# File 'lib/linux/lxc/line.rb', line 6

def initialize(lxc, key, value)
  @lxc = lxc
  @line = lxc && lxc.lines.add(self).length
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/linux/lxc/line.rb', line 4

def key
  @key
end

#lineObject (readonly)

Returns the value of attribute line.



4
5
6
# File 'lib/linux/lxc/line.rb', line 4

def line
  @line
end

#lxcObject (readonly)

Returns the value of attribute lxc.



4
5
6
# File 'lib/linux/lxc/line.rb', line 4

def lxc
  @lxc
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/linux/lxc/line.rb', line 5

def value
  @value
end

Instance Method Details

#comment!Object



17
18
19
20
21
22
23
24
25
# File 'lib/linux/lxc/line.rb', line 17

def comment!
  return if @key == '#'
  # remove from index
  lxc.remove_from_index(self)
  uncomment = to_s
  @key = '#'
  @value = '# ' + uncomment
  lxc.add_to_index(self)
end

#fileObject



13
14
15
# File 'lib/linux/lxc/line.rb', line 13

def file
  @lxc.file
end

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/linux/lxc/line.rb', line 27

def to_s
  if value
    if key == '#'
      value
    else
      "#{key} = #{value}"
    end
  else
    key
  end
end