Class: Addic7edDownloader::Subtitle
- Inherits:
-
Object
- Object
- Addic7edDownloader::Subtitle
- Includes:
- Comparable
- Defined in:
- lib/addic7ed_downloader/subtitle.rb
Instance Attribute Summary collapse
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#language ⇒ Object
Returns the value of attribute language.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#url ⇒ Object
Returns the value of attribute url.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
We can sort by downloads number.
- #completed? ⇒ Boolean
- #hearing_impaired? ⇒ Boolean
-
#initialize(nokogiri_fragment) ⇒ Subtitle
constructor
A new instance of Subtitle.
- #to_s ⇒ Object
- #works_with?(tag) ⇒ Boolean
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
#downloads ⇒ Object
Returns the value of attribute downloads.
4 5 6 |
# File 'lib/addic7ed_downloader/subtitle.rb', line 4 def downloads @downloads end |
#language ⇒ Object
Returns the value of attribute language.
4 5 6 |
# File 'lib/addic7ed_downloader/subtitle.rb', line 4 def language @language end |
#notes ⇒ Object
Returns the value of attribute notes.
4 5 6 |
# File 'lib/addic7ed_downloader/subtitle.rb', line 4 def notes @notes end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/addic7ed_downloader/subtitle.rb', line 4 def url @url end |
#version ⇒ Object
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
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
33 34 35 |
# File 'lib/addic7ed_downloader/subtitle.rb', line 33 def hearing_impaired? @hi end |
#to_s ⇒ Object
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
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 |