class Object
Constants
- BASIC_USAGE
Define various command line option sets here
- OptionSet
Public Instance Methods
apply_options(options={})
click to toggle source
# File lib/showrobot/cli/options.rb, line 39 def apply_options options={} require 'showrobot' options.each do |key, value| # if the value is nil, skip next if not options.include?((key.to_s + '_given').to_sym) or value.nil? case key when :config_file ShowRobot.configure :config_file => options[:config_file] ShowRobot.load_config when :cache_dir, :tv_database, :movie_database, :verbose ShowRobot.configure key, value when :no_cache ShowRobot.configure :use_cache, false when :clear_cache puts "Clearing cache in [ #{ShowRobot.config[:cache_dir]} ]" if ShowRobot.config[:verbose] File.delete(*Dir[ShowRobot.config[:cache_dir] + '/*.cache']) end end end
identify(media, database, prompt)
click to toggle source
helper function for identifying a file
# File lib/showrobot/cli/identify.rb, line 2 def identify media, database, prompt if media.is_movie? else db = ShowRobot.create_datasource database db.mediaFile = media db.series = if prompt select db.series_list, "Select a series for [ #{media.fileName} ]" do |i, item| sprintf " %3d) %s", i, item[:name] end else db.series_list.first end if prompt select db.episode_list, "Select an episode for [ #{media.fileName} ]" do |i, item| sprintf " %3d) [%02d.%02d] %s", i, item[:season], item[:episode], item[:title] end else db.episode media.season, media.episode end end end
select(list, prompt, &format)
click to toggle source
helper function for prompts
# File lib/showrobot/cli/select.rb, line 2 def select list, prompt, &format range = 0...10 begin puts prompt range.each do |i| puts format.call i, list[i] end print " > " input = $stdin.gets.chomp case input when /^[\d]+$/ # it's a number, make sure it's in the range selected = list[input.to_i] if input.to_i < list.length when 'n' # next range range = Range.new(range.end, [range.end + 10, list.length].min, true) if range.end < list.length when 'p' # prev range range = Range.new([0, range.first - 10].max, range.first, true) if range.first > 1 when 'q' exit end end while selected.nil? selected end
translate(str, mapping)
click to toggle source
# File lib/showrobot/cli/translate.rb, line 1 def translate str, mapping str.gsub(/(?<!\\){[^}]+}/, mapping).gsub(/\\({[^}]+})/, '\1') end