Class: IniParse::Lines::Option
- Inherits:
-
Object
- Object
- IniParse::Lines::Option
- Includes:
- Line
- Defined in:
- lib/iniparse/lines.rb
Overview
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
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .parse(line, opts) ⇒ Object
-
.typecast(value) ⇒ Object
Attempts to typecast values.
Instance Method Summary collapse
-
#initialize(key, value, opts = {}) ⇒ Option
constructor
Parameters key<String>:: The option key.
Methods included from Line
#blank?, #comment, #has_comment?, #to_ini
Constructor Details
#initialize(key, value, opts = {}) ⇒ Option
Parameters
- key<String>
-
The option key.
- value<String>
-
The value for this option.
- opts<Hash>
-
Extra options for the line.
247 248 249 250 |
# File 'lib/iniparse/lines.rb', line 247 def initialize(key, value, opts = {}) super(opts) @key, @value = key.to_s, value end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
240 241 242 |
# File 'lib/iniparse/lines.rb', line 240 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
240 241 242 |
# File 'lib/iniparse/lines.rb', line 240 def value @value end |
Class Method Details
.parse(line, opts) ⇒ Object
252 253 254 255 256 |
# 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) ⇒ Object
Attempts to typecast values.
259 260 261 262 263 264 265 266 267 268 |
# 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 |