Class: TrackList::TemplateParser

Inherits:
Object
  • Object
show all
Defined in:
lib/track_list/template_parser.rb

Overview

A helper class to read/write a config file.

Instance Method Summary collapse

Constructor Details

#initializeTemplateParser

Pass in a file path to read/write the config file.



13
14
15
16
# File 'lib/track_list/template_parser.rb', line 13

def initialize
    environment = Environment.new
    @config_path = environment.get_config_path
end

Instance Method Details

#config_exists?Boolean

Check if the config file already exists.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/track_list/template_parser.rb', line 26

def config_exists?
    if File.exist?(File.expand_path(@config_path))
        true
    else
        false
    end
end

#create_default_configObject

Create a default config file with some basic settings.



36
37
38
39
40
41
42
# File 'lib/track_list/template_parser.rb', line 36

def create_default_config
    config = { "output" => "%TRACK%. %TITLE% (%LENGTH%)" }
    FileUtils.mkdir_p File.dirname(@config_path)
    out_file = File.new(File.expand_path(@config_path), 'w')
    out_file.puts(config.to_yaml)
    out_file.close
end

#loadObject

Return the config file in a Ruby-readable format.



20
21
22
# File 'lib/track_list/template_parser.rb', line 20

def load
    YAML.load(File.open(File.expand_path(@config_path)))
end