Class: SubtitleSource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ SubtitleSource

Returns a new instance of SubtitleSource.



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

def initialize(api_key)
  @api_key = api_key
  unless @api_key
    raise ArgumentError.new("You must specify an Subtitle Source API key.")
  end
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

Instance Method Details

#fetchObject



42
43
44
# File 'lib/subtitle_source.rb', line 42

def fetch
  content
end

#imdb(imdb) ⇒ Object



31
32
33
34
35
36
# File 'lib/subtitle_source.rb', line 31

def imdb(imdb)
  tap do 
    @imdb = imdb.to_s.match(/^(tt)?(\d+)/).to_a[2]
    @language = nil; @query = nil
  end
end

#language(language) ⇒ Object



24
25
26
27
28
29
# File 'lib/subtitle_source.rb', line 24

def language(language)
  tap do 
    @language = language.to_s.downcase
    @imdb = nil
  end
end

#page(page) ⇒ Object



38
39
40
# File 'lib/subtitle_source.rb', line 38

def page(page)
  tap { @page = page - 1 }
end

#query(query) ⇒ Object



17
18
19
20
21
22
# File 'lib/subtitle_source.rb', line 17

def query(query)
  tap do 
    @query = URI.escape(query)
    @imdb = nil
  end
end