class Bathyscaphe::Config
Constants
- OPTIONS
Public Class Methods
config_dir()
click to toggle source
Returns full path to the directory where config file is located.
# File lib/bathyscaphe/config.rb, line 101 def self.config_dir File.dirname( config_filename ) end
config_filename()
click to toggle source
Returns full path to config file.
# File lib/bathyscaphe/config.rb, line 94 def self.config_filename File.expand_path( CONFIG_FILENAME ) end
load()
click to toggle source
Loads configuration parameters.
# File lib/bathyscaphe/config.rb, line 58 def self.load @params = CONFIG_DEFAULTS if File.exists? config_filename @params.merge! YAML::load_file( config_filename ) end end
method_missing( name, *args )
click to toggle source
Returns a property with the given name.
# File lib/bathyscaphe/config.rb, line 81 def self.method_missing( name, *args ) if m = /^(.+)=$/.match(name.to_s) # set @params[m[1].to_sym] = args[0] else # get @params[name.to_sym] end end
parse_options()
click to toggle source
# File lib/bathyscaphe/config.rb, line 22 def self.parse_options options = {} optparser = OptionParser.new do |opts| opts.set_summary_indent(' ') opts.banner = "Usage: #{File.basename($0)} [OPTIONS] TV_SHOW" # opts.on( "-s", "--source SOURCE", String, "Set source to download subtitles from","Current: #{self.source}" ) { |o| self.source = o ; self.save } opts.on( "-d", "--dry-run", "Parse filename but do not download anything") { |o| OPTIONS[:dry_run] = o} opts.on( "-v", "--version", "Show version") do options[:version] = true puts Bathyscaphe::VERSION end opts.on_tail( "-h", "--help", "Show usage") do puts opts exit end end # Parse command line begin optparser.parse! if ARGV.empty? puts optparser unless options[:version] exit else tv_show = ARGV[0] end rescue OptionParser::ParseError => e puts e puts optparser exit end return tv_show end
save()
click to toggle source
Writes configuration parameters, creating config directory and file if they do not exist.
# File lib/bathyscaphe/config.rb, line 69 def self.save unless File.directory? config_dir system "mkdir -p #{config_dir}" end File.open( config_filename, "w" ) do |f| YAML::dump( @params, f ) end end