Class: RCFile
- Inherits:
-
Object
- Object
- RCFile
- Defined in:
- lib/riel/rcfile.rb
Overview
Represents a resource file, where ‘#’ is used to comment to end of lines, and name/value pairs are separated by ‘=’ or ‘:’.
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#initialize(args = Hash.new, &blk) ⇒ RCFile
constructor
Reads the RC file, if it exists, and if a block is passed, calls the block with each name/value pair, which are also accessible via
settings.
Constructor Details
#initialize(args = Hash.new, &blk) ⇒ RCFile
Reads the RC file, if it exists, and if a block is passed, calls the block with each name/value pair, which are also accessible via settings.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/riel/rcfile.rb', line 13 def initialize args = Hash.new, &blk @settings = Array.new unless lines = args[:lines] if fname = args[:filename] lines = IO::readlines fname end end cmtre = Regexp.new '\s*#.*' nvre = Regexp.new '\s*[=:]\s*' lines.each do |line| line.sub! cmtre, '' name, value = line.split nvre if name && value name.strip! value.strip! @settings << [ name, value ] if blk blk.call name, value end end end end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
8 9 10 |
# File 'lib/riel/rcfile.rb', line 8 def settings @settings end |