class IniParse::Lines::Option

Represents probably the most common type of line in an INI document: an option. Consists of a key and value, usually separated with an =.

key = value

Attributes

key[RW]
value[RW]

Public Class Methods

new(key, value, opts = {}) click to toggle source

Parameters

key<String>

The option key.

value<String>

The value for this option.

opts<Hash>

Extra options for the line.

Calls superclass method IniParse::Lines::Line::new
# File lib/iniparse/lines.rb, line 247
def initialize(key, value, opts = {})
  super(opts)
  @key, @value = key.to_s, value
end
parse(line, opts) click to toggle source
# File lib/iniparse/lines.rb, line 252
def self.parse(line, opts)
  if m = @regex.match(line)
    [:option, m[1].strip, typecast(m[2].strip), opts]
  end
end
typecast(value) click to toggle source

Attempts to typecast values.

# File lib/iniparse/lines.rb, line 259
def self.typecast(value)
  case value
    when /^\s*$/                                        then nil
    when /^-?(?:\d|[1-9]\d+)$/                          then Integer(value)
    when /^-?(?:\d|[1-9]\d+)(?:\.\d+)?(?:e[+-]?\d+)?$/i then Float(value)
    when /true/i                                        then true
    when /false/i                                       then false
    else                                                     value
  end
end

Private Instance Methods

line_contents() click to toggle source
# File lib/iniparse/lines.rb, line 274
def line_contents
  '%s = %s' % [key, value]
end