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.



165
166
167
168
169
170
171
# File 'lib/rconftool.rb', line 165

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.



163
164
165
# File 'lib/rconftool.rb', line 163

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



162
163
164
# File 'lib/rconftool.rb', line 162

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



162
163
164
# File 'lib/rconftool.rb', line 162

def version
  @version
end

Instance Method Details

#<<(str) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/rconftool.rb', line 172

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 ‘#’



181
182
183
# File 'lib/rconftool.rb', line 181

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

#to_sObject



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

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