Class: Distincter2::D2ConfigParser
- Inherits:
-
Object
- Object
- Distincter2::D2ConfigParser
- Defined in:
- lib/distincter2/config.rb
Overview
Class representing a parser for Distincter2 configuration files.
Instance Method Summary collapse
-
#initialize(config_path) ⇒ D2ConfigParser
constructor
Initializes a new instance of D2ConfigParser.
-
#parse ⇒ Distincter2::D2Config
Parses the configuration file and returns a D2Config object.
Constructor Details
#initialize(config_path) ⇒ D2ConfigParser
Initializes a new instance of D2ConfigParser.
45 46 47 |
# File 'lib/distincter2/config.rb', line 45 def initialize(config_path) @config_path = config_path end |
Instance Method Details
#parse ⇒ Distincter2::D2Config
Parses the configuration file and returns a D2Config object.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/distincter2/config.rb', line 52 def parse exclude_paths = [] version = 'v1' # Open the configuration file and read its lines. ::File.open(@config_path, 'r') do |file| file.readlines.each do |line| l = line.strip # Skip lines that contain the version number or are empty. next if l == 'v1' || l.empty? # Add the non-empty, non-version lines to the exclude_paths array. exclude_paths << l end end # Create a new D2Config object with the parsed exclude_paths and version. ::Distincter2::D2Config.new(exclude_paths, version) end |