Class: Moviesort::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/moviesort/command_line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ CommandLine

Returns a new instance of CommandLine.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moviesort/command_line.rb', line 13

def initialize(argv = ARGV)
  @options = Trollop.options(argv) do
    banner <<-EOS.gsub(/^ {8}/, '')
    Moviesort is a script to sort and file away your TV shows and movies

    Usage: moviesort [options]
    EOS

    opt :source, "Source directory", :default => '.'
    opt :target, "Target directory", :default => '.'
    opt :notifiers, "Notifiers", :type => :string, :multi => true
    opt :twitteruser
    opt :twitterpass
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/moviesort/command_line.rb', line 7

def options
  @options
end

Class Method Details

.parse(options) ⇒ Object



9
10
11
# File 'lib/moviesort/command_line.rb', line 9

def self.parse(options)
  new(options.split)
end

Instance Method Details

#notifiersObject



35
36
37
38
39
40
41
# File 'lib/moviesort/command_line.rb', line 35

def notifiers
  notifiers = []
  if @options[:notifiers].include?('twitter')
    notifiers << Moviesort::Notifiers::Twitter.new(@options[:twitteruser], @options[:twitterpass])
  end
  return notifiers
end

#runObject



29
30
31
32
33
# File 'lib/moviesort/command_line.rb', line 29

def run
  sorter = Sorter::TV.new(@options[:target])
  notifiers.each { |note| sorter.add_notifier(note) }
  sorter.sort_directory(@options[:source])
end