Class: Addic7edDownloader::Subtitle

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/addic7ed_downloader/subtitle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_fragment) ⇒ Subtitle

Returns a new instance of Subtitle.



6
7
8
9
10
11
12
13
14
# File 'lib/addic7ed_downloader/subtitle.rb', line 6

def initialize(nokogiri_fragment)
  @version  = nokogiri_fragment.at('.NewsTitle').text[/\AVersion (.*?),/, 1]
  @language = nokogiri_fragment.at('.language').text.strip
  @complete = nokogiri_fragment.at('table tr:nth-child(3) td:nth-child(4)').text.strip
  @url = generate_download_url(nokogiri_fragment)
  @notes = nokogiri_fragment.at('.newsDate').text.strip
  @hi = nokogiri_fragment.css('.newsDate').last.children[1]['title'] == 'Hearing Impaired'
  @downloads = nokogiri_fragment.css('.newsDate').last.text[/(\d+) Downloads/, 1].to_i
end

Instance Attribute Details

#downloadsObject

Returns the value of attribute downloads.



4
5
6
# File 'lib/addic7ed_downloader/subtitle.rb', line 4

def downloads
  @downloads
end

#languageObject

Returns the value of attribute language.



4
5
6
# File 'lib/addic7ed_downloader/subtitle.rb', line 4

def language
  @language
end

#notesObject

Returns the value of attribute notes.



4
5
6
# File 'lib/addic7ed_downloader/subtitle.rb', line 4

def notes
  @notes
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/addic7ed_downloader/subtitle.rb', line 4

def url
  @url
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/addic7ed_downloader/subtitle.rb', line 4

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object

We can sort by downloads number



24
25
26
# File 'lib/addic7ed_downloader/subtitle.rb', line 24

def <=>(other)
  @downloads <=> other.downloads
end

#completed?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/addic7ed_downloader/subtitle.rb', line 28

def completed?
  # 'Completed' or '33.37% Completed'
  @complete == 'Completed'
end

#hearing_impaired?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/addic7ed_downloader/subtitle.rb', line 33

def hearing_impaired?
  @hi
end

#to_sObject



16
17
18
19
20
21
# File 'lib/addic7ed_downloader/subtitle.rb', line 16

def to_s
  "Version #{@version} " \
  "(#{@language}#{', Hearing Impaired' if @hi})" \
  "#{': ' << @notes unless @notes.empty?}" \
  " [#{@downloads} Downloads]"
end

#works_with?(tag) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/addic7ed_downloader/subtitle.rb', line 37

def works_with?(tag)
  @version.include?(tag) || @notes[/works? with \"?([^\"\s]+)/i, 1].to_s.include?(tag)
end