Class: Bathyscaphe::Config
Constant Summary collapse
- OPTIONS =
{ :dry_run => false }
Class Method Summary collapse
-
.config_dir ⇒ Object
Returns full path to the directory where config file is located.
-
.config_filename ⇒ Object
Returns full path to config file.
-
.load ⇒ Object
Loads configuration parameters.
-
.method_missing(name, *args) ⇒ Object
Returns a property with the given name.
- .parse_options ⇒ Object
-
.save ⇒ Object
Writes configuration parameters, creating config directory and file if they do not exist.
Class Method Details
.config_dir ⇒ Object
Returns full path to the directory where config file is located.
101 102 103 |
# File 'lib/bathyscaphe/config.rb', line 101 def self.config_dir File.dirname( config_filename ) end |
.config_filename ⇒ Object
Returns full path to config file.
94 95 96 |
# File 'lib/bathyscaphe/config.rb', line 94 def self.config_filename File.( CONFIG_FILENAME ) end |
.load ⇒ Object
Loads configuration parameters.
58 59 60 61 62 63 |
# 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) ⇒ Object
Returns a property with the given name.
81 82 83 84 85 86 87 88 89 |
# 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 ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bathyscaphe/config.rb', line 22 def self. = {} optparser = OptionParser.new do |opts| opts.set_summary_indent(' ') opts. = "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 [: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 [:version] exit else tv_show = ARGV[0] end rescue OptionParser::ParseError => e puts e puts optparser exit end return tv_show end |
.save ⇒ Object
Writes configuration parameters, creating config directory and file if they do not exist.
69 70 71 72 73 74 75 76 |
# 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 |