Module: IniParse::Lines::Line

Included in:
Blank, Option, Section
Defined in:
lib/iniparse/lines.rb

Overview

A base class from which other line types should inherit.

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns whether this is a line which has no data.

Returns:

  • (Boolean)


48
49
50
# File 'lib/iniparse/lines.rb', line 48

def blank?
  false
end

#commentObject

Returns the inline comment for this line. Includes the comment separator at the beginning of the string.



43
44
45
# File 'lib/iniparse/lines.rb', line 43

def comment
  "#{ @comment_sep }#{ @comment_prefix }#{ @comment }"
end

#has_comment?Boolean

Returns if this line has an inline comment.

Returns:

  • (Boolean)


17
18
19
# File 'lib/iniparse/lines.rb', line 17

def has_comment?
  not @comment.nil?
end

#initialize(opts = {}) ⇒ Object

Parameters

opts<Hash>

Extra options for the line.



8
9
10
11
12
13
14
# File 'lib/iniparse/lines.rb', line 8

def initialize(opts = {})
  @comment        = opts.fetch(:comment, nil)
  @comment_sep    = opts.fetch(:comment_sep, ';')
  @comment_prefix = opts.fetch(:comment_prefix, ' ')
  @comment_offset = opts.fetch(:comment_offset, 0)
  @indent         = opts.fetch(:indent, '')
end

#line_contentsObject

Returns the contents for this line.



37
38
39
# File 'lib/iniparse/lines.rb', line 37

def line_contents
  ''
end

#to_iniObject

Returns this line as a string as it would be represented in an INI document.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iniparse/lines.rb', line 23

def to_ini
  ini = line_contents
  ini = @indent + ini if @indent

  if has_comment?
    ini += ' ' if ini =~ /\S/ # not blank
    ini  = ini.ljust(@comment_offset)
    ini += comment
  end

  ini
end