class Dotini::KeyValuePair

Key/value pair, with optional prepended and inline comments

Attributes

inline_comment[RW]
key[RW]
prepended_comments[RW]
value[RW]

Public Class Methods

new() click to toggle source

Creates a new, undefined key/value pair with no comments

# File lib/dotini/key_value_pair.rb, line 9
def initialize
  @key = nil
  @value = nil
  @prepended_comments = []
  @inline_comment = nil
end

Public Instance Methods

to_s() click to toggle source

Represents the key/value pair as a string

# File lib/dotini/key_value_pair.rb, line 17
def to_s
  buffer = StringIO.new
  prepended_comments.each do |line|
    buffer << line << "\n"
  end

  unless key.nil?
    buffer << "#{key} = #{value}"
    buffer <<
      if inline_comment.nil?
        "\n"
      else
        " #{inline_comment}\n"
      end
  end

  buffer.string
end