Class: TrackList::TemplateParser
- Inherits:
-
Object
- Object
- TrackList::TemplateParser
- Defined in:
- lib/track_list/template_parser.rb
Overview
A helper class to read/write a config file.
Instance Method Summary collapse
-
#config_exists? ⇒ Boolean
Check if the config file already exists.
-
#create_default_config ⇒ Object
Create a default config file with some basic settings.
-
#initialize ⇒ TemplateParser
constructor
Pass in a file path to read/write the config file.
-
#load ⇒ Object
Return the config file in a Ruby-readable format.
Constructor Details
#initialize ⇒ TemplateParser
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.
26 27 28 29 30 31 32 |
# File 'lib/track_list/template_parser.rb', line 26 def config_exists? if File.exist?(File.(@config_path)) true else false end end |
#create_default_config ⇒ Object
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.(@config_path), 'w') out_file.puts(config.to_yaml) out_file.close end |
#load ⇒ Object
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.(@config_path))) end |