Class: SeriesTimer::Application

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Application

Returns a new instance of Application.



12
13
14
# File 'lib/series_timer.rb', line 12

def initialize(argv)
  @params, @series = parse_options(argv)
end

Instance Method Details

#parse_options(argv) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/series_timer.rb', line 16

def parse_options(argv)
  params = {}
  parser = OptionParser.new
  parser.on("-f") { params[:options] = :force }
  parser.on("-n") { params[:episodes] = :next }
  parser.on("-l") { params[:episodes] = :last }
  parser.on("-a") { params[:episodes] = :all }
  series = parser.parse(argv)
  raise ArgumentError if series.empty?
  [params, series]
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/series_timer.rb', line 28

def run
  @series.each do |serie|
    case @params[:episodes]
      when :last
        puts SeriesManager.last_episode(serie, @params[:options])
      when :all
        puts SeriesManager.all_episodes(serie, @params[:options])
      else
        puts SeriesManager.next_episode(serie, @params[:options])
      end
  end
end