Class: Joggle::ConfigParser
- Inherits:
-
Object
- Object
- Joggle::ConfigParser
- Defined in:
- lib/joggle/config-parser.rb
Overview
Simple configuration file parser.
Class Method Summary collapse
-
.run(path, &block) ⇒ Object
Parse configuration file and pass each directive to the specified block.
Instance Method Summary collapse
-
#initialize(path) ⇒ ConfigParser
constructor
Create a new config file parser.
-
#run(&block) ⇒ Object
Parse configuration file and pass each directive to the specified block.
Constructor Details
#initialize(path) ⇒ ConfigParser
Create a new config file parser.
17 18 19 |
# File 'lib/joggle/config-parser.rb', line 17 def initialize(path) @path = path end |
Class Method Details
.run(path, &block) ⇒ Object
Parse configuration file and pass each directive to the specified block.
10 11 12 |
# File 'lib/joggle/config-parser.rb', line 10 def self.run(path, &block) new(path).run(&block) end |
Instance Method Details
#run(&block) ⇒ Object
Parse configuration file and pass each directive to the specified block.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/joggle/config-parser.rb', line 25 def run(&block) File.readlines(@path).each do |line| next if line =~ /\s*#/ || line !~ /\S/ line = line.strip key, val = line.split(/\s+/, 2) if key && key.size > 0 block.call(key, val) end end end |