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
The option key.
The value for this option.
Extra options for the line.
# File lib/iniparse/lines.rb, line 265 def initialize(key, value, opts = {}) super(opts) @key, @value = key.to_s, value @option_sep = opts.fetch(:option_sep, ' = ') end
# File lib/iniparse/lines.rb, line 271 def self.parse(line, opts) if m = @regex.match(line) opts[:option_sep] = m[2] [:option, m[1].strip, typecast(m[3].strip), opts] end end
Attempts to typecast values.
# File lib/iniparse/lines.rb, line 279 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+)?$/ then Float(value) when /^true$/ then true when /^false$/ then false else value end end