Class: WhereTo::Locator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Locator

Returns a new instance of Locator.



10
11
12
13
14
15
# File 'lib/where_to/locator.rb', line 10

def initialize(hash = {})
  load_values_from hash
  if series_id
    @series_title = WhereTo::TVDB.new(params).lookup_series(series_id).name
  end
end

Instance Attribute Details

#airdateObject

Returns the value of attribute airdate.



7
8
9
# File 'lib/where_to/locator.rb', line 7

def airdate
  @airdate
end

#episode_extensionObject

Returns the value of attribute episode_extension.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def episode_extension
  @episode_extension
end

#episode_numberObject

Returns the value of attribute episode_number.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def episode_number
  @episode_number
end

#episode_qualityObject

Returns the value of attribute episode_quality.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def episode_quality
  @episode_quality
end

#episode_titleObject

Returns the value of attribute episode_title.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def episode_title
  @episode_title
end

#groupObject

Returns the value of attribute group.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def group
  @group
end

#seasonObject

Returns the value of attribute season.



7
8
9
# File 'lib/where_to/locator.rb', line 7

def season
  @season
end

#season_airdateObject

Returns the value of attribute season_airdate.



7
8
9
# File 'lib/where_to/locator.rb', line 7

def season_airdate
  @season_airdate
end

#series_idObject

Returns the value of attribute series_id.



8
9
10
# File 'lib/where_to/locator.rb', line 8

def series_id
  @series_id
end

#series_titleObject

Returns the value of attribute series_title.



7
8
9
# File 'lib/where_to/locator.rb', line 7

def series_title
  @series_title
end

Instance Method Details

#locate(hash = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/where_to/locator.rb', line 17

def locate(hash = {})
  load_values_from hash
  validate!

  output = WhereTo.configuration.folder_format
  output.gsub! '%series_title',   series_title
  output.gsub! '%season_number',  season.to_s
  output.gsub! '%season_airdate', season_airdate.to_s

  if episode_title and episode_number
    formatter = WhereTo::EpisodeFormatter.new params
    output << formatter.format!
  end

  WhereTo::Location.new output
end

#lookup!Object



40
41
42
43
# File 'lib/where_to/locator.rb', line 40

def lookup!
  tvdb = WhereTo::TVDB.new params
  load_values_from tvdb.lookup!
end

#paramsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/where_to/locator.rb', line 45

def params
  _params = {}
  _params[:series_title]   = series_title
  _params[:season_number]  = season
  _params[:episode_title]  = episode_title
  _params[:episode_number] = episode_number
  _params[:quality]        = episode_quality
  _params[:extension]      = episode_extension
  _params[:group]          = group
  _params[:series_id]      = series_id
  _params
end

#validate!Object



34
35
36
37
38
# File 'lib/where_to/locator.rb', line 34

def validate!
  raise 'A season airdate is required to locate an episode' if season_airdate == nil
  raise 'A season number is required to locate an episode' if season.nil?
  true
end