Class: Rconftool::Setting

Inherits:
Object show all
Defined in:
lib/rconftool.rb

Overview

Object to represent a single setting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ Setting

Returns a new instance of Setting.



169
170
171
172
173
174
175
# File 'lib/rconftool.rb', line 169

def initialize(name, version)
  @name = name.gsub(/\s+/,'')
  @version = version.gsub(/s+/,'')
  @comment = ""
  @content = ""
  @in_content = false
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



167
168
169
# File 'lib/rconftool.rb', line 167

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



166
167
168
# File 'lib/rconftool.rb', line 166

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



166
167
168
# File 'lib/rconftool.rb', line 166

def version
  @version
end

Instance Method Details

#<<(str) ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/rconftool.rb', line 176

def <<(str)
  @in_content = true unless /\A#/ =~ str
  if @in_content
    @content << str
  else
    @comment << str
  end
end

#add_comment(str) ⇒ Object

Add text to ‘comment’ portion of setting, prefixing each line with ‘#’



185
186
187
# File 'lib/rconftool.rb', line 185

def add_comment(str)
  @comment << str.gsub(/^/,'#')
end

#to_sObject



188
189
190
191
# File 'lib/rconftool.rb', line 188

def to_s
  return "#{@comment}#{@content}" if @name == HEADER_ID
  return "##NAME: #{@name}:#{@version}\n#{@comment}#{@content}"
end