class Addic7edDownloader::Subtitle
Attributes
downloads[RW]
language[RW]
notes[RW]
url[RW]
version[RW]
Public Class Methods
new(nokogiri_fragment)
click to toggle source
# 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
Public Instance Methods
<=>(other)
click to toggle source
We can sort by downloads number
# File lib/addic7ed_downloader/subtitle.rb, line 24 def <=>(other) @downloads <=> other.downloads end
completed?()
click to toggle source
# File lib/addic7ed_downloader/subtitle.rb, line 28 def completed? # 'Completed' or '33.37% Completed' @complete == 'Completed' end
hearing_impaired?()
click to toggle source
# File lib/addic7ed_downloader/subtitle.rb, line 33 def hearing_impaired? @hi end
to_s()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
generate_download_url(nokogiri_fragment)
click to toggle source
# File lib/addic7ed_downloader/subtitle.rb, line 43 def generate_download_url(nokogiri_fragment) links = nokogiri_fragment.css('.buttonDownload') case links.length when 1 links[0]['href'] # If there are two download buttons, the second is the "most updated" when 2 links[1]['href'] end end