Module: IniParse::Lines::Line
Overview
A base class from which other line types should inherit.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Returns whether this is a line which has no data.
-
#comment ⇒ Object
Returns the inline comment for this line.
-
#has_comment? ⇒ Boolean
Returns if this line has an inline comment.
-
#initialize(opts = {}) ⇒ Object
Parameters opts<Hash>:: Extra options for the line.
-
#line_contents ⇒ Object
Returns the contents for this line.
-
#options ⇒ Object
Returns the options used to create the line.
-
#to_ini ⇒ Object
Returns this line as a string as it would be represented in an INI document.
Instance Method Details
#blank? ⇒ Boolean
Returns whether this is a line which has no data.
47 48 49 |
# File 'lib/iniparse/lines.rb', line 47 def blank? false end |
#comment ⇒ Object
Returns the inline comment for this line. Includes the comment separator at the beginning of the string.
42 43 44 |
# File 'lib/iniparse/lines.rb', line 42 def comment "#{ @comment_sep }#{ @comment_prefix }#{ @comment }" end |
#has_comment? ⇒ Boolean
Returns if this line has an inline comment.
18 19 20 |
# File 'lib/iniparse/lines.rb', line 18 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 15 |
# 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, '') @option_sep = opts.fetch(:option_sep, nil) end |
#line_contents ⇒ Object
Returns the contents for this line.
36 37 38 |
# File 'lib/iniparse/lines.rb', line 36 def line_contents '' end |
#options ⇒ Object
Returns the options used to create the line
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/iniparse/lines.rb', line 52 def { comment: @comment, comment_sep: @comment_sep, comment_prefix: @comment_prefix, comment_offset: @comment_offset, indent: @indent, option_sep: @option_sep } end |
#to_ini ⇒ Object
Returns this line as a string as it would be represented in an INI document.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/iniparse/lines.rb', line 24 def to_ini [*line_contents].map { |ini| if has_comment? ini += ' ' if ini =~ /\S/ # not blank ini = ini.ljust(@comment_offset) ini += comment end @indent + ini }.join "\n" end |