addic7ed 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6af440920aab856b3b6d6c0329a77156c798132f
4
- data.tar.gz: 368155bf890e2f5335c5c455cc140f7c96af06bc
3
+ metadata.gz: 0d3890d1e46e13f0c3723d7920aafd15010445ff
4
+ data.tar.gz: 26c22db148789cfe188f49b2b9dbd36ac77ade91
5
5
  SHA512:
6
- metadata.gz: 6f01f1ca16e06692ecd6dfe37ff6a25a35ed2fd5e1c637c9f7c6e050588dda18abe34d1a0a2b21e6706593eb9575acd07096d2fa32afb4273ba28ef4ddf19be6
7
- data.tar.gz: d54a2a68b30f26f3acd617765300b3dce82583b3ec025ff20bd09d2137fc095bb1ab28ea644e4cd96ba95d928a8a543780b7f2e4f4c99d5ae096e0431020d897
6
+ metadata.gz: dc559f309a1fc2a4fdb7cd891ca464afc4db7ee5027961b70c7768f33b64c5e5ae16d69184eea4ffd682671c679c3ad2aec657a298753d5e4c7ce1bac9f6b6e6
7
+ data.tar.gz: 3cbd2bd9e0283ac42695fcae3e39e0fde44020257c2ab9e5314a0a58c0c4d832f932d7ae933fbf2cba2b5a77c0287c8e9073be9943b89faba51d69e5732f9234
@@ -14,7 +14,7 @@ module Addic7ed
14
14
  def url(lang = 'fr')
15
15
  check_language_availability(lang)
16
16
  @localized_urls ||= {}
17
- @localized_urls[lang] ||= "http://www.addic7ed.com/serie/#{ShowList.find(video_file.showname)}/#{video_file.season}/#{video_file.episode}/#{LANGUAGES[lang][:id]}"
17
+ @localized_urls[lang] ||= "http://www.addic7ed.com/serie/#{ShowList.url_segment_for(video_file.showname)}/#{video_file.season}/#{video_file.episode}/#{LANGUAGES[lang][:id]}"
18
18
  end
19
19
 
20
20
  def subtitles(lang = 'fr')
@@ -6,31 +6,36 @@ module Addic7ed
6
6
  @raw_name = raw_name
7
7
  end
8
8
 
9
- def self.find(raw_name)
10
- new(raw_name).find
9
+ def self.url_segment_for(raw_name)
10
+ new(raw_name).url_segment_for
11
11
  end
12
12
 
13
- def find
14
- matching_shows = human_list.select{ |i| [i, human_name].map(&:downcase).reduce(:==) }
13
+ def url_segment_for
15
14
  raise ShowNotFound if matching_shows.empty?
16
15
  matching_shows.first.gsub(' ', '_')
17
16
  end
18
17
 
19
18
  private
20
19
 
21
- def human_name
22
- @human_name ||= raw_name.
23
- gsub(/[_\.]+/, ' ').
24
- gsub(/ (US|UK)( |$)/i, ' (\1)\2').
25
- gsub(/ (\d{4})( |$)/i, ' (\1)\2')
20
+ def humanized_name
21
+ @humanized_name ||= raw_name.
22
+ gsub(/[_\.]+/, ' ').
23
+ gsub(/ (US|UK)( |$)/i, ' (\1)\2').
24
+ gsub(/ (\d{4})( |$)/i, ' (\1)\2')
26
25
  end
27
26
 
28
- def human_list
29
- @@human_list ||= Nokogiri::HTML(addic7ed_homepage.body).css("select#qsShow option:not(:first-child)").map(&:text)
27
+ def matching_shows
28
+ @matching_shows ||= addic7ed_shows.select do |addic7ed_show|
29
+ [addic7ed_show, humanized_name].map{ |showname| showname.downcase.gsub("'", "") }.reduce(:==)
30
+ end
31
+ end
32
+
33
+ def addic7ed_shows
34
+ @@addic7ed_shows ||= Nokogiri::HTML(addic7ed_homepage.body).css("select#qsShow option:not(:first-child)").map(&:text)
30
35
  end
31
36
 
32
37
  def addic7ed_homepage
33
- Net::HTTP.start("www.addic7ed.com", 80) do |http|
38
+ Net::HTTP.start("www.addic7ed.com") do |http|
34
39
  request = Net::HTTP::Get.new("/")
35
40
  request["User-Agent"] = USER_AGENTS.sample
36
41
  http.request(request)
@@ -1,3 +1,3 @@
1
1
  module Addic7ed
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -1,33 +1,33 @@
1
1
  require "spec_helper"
2
2
  require "./lib/addic7ed"
3
3
 
4
- describe Addic7ed::ShowList, ".find" do
4
+ describe Addic7ed::ShowList, ".url_segment_for" do
5
5
  it "changes all spaces to underscores" do
6
- expect(Addic7ed::ShowList.find("The Walking Dead")).to eq "The_Walking_Dead"
6
+ expect(Addic7ed::ShowList.url_segment_for("The.Walking.Dead")).to eq "The_Walking_Dead"
7
7
  end
8
8
 
9
9
  it "wraps country code with parenthesis" do
10
- expect(Addic7ed::ShowList.find("Shameless.US")).to eq "Shameless_(US)"
11
- expect(Addic7ed::ShowList.find("Vikings.UK")).to eq "Vikings_(UK)"
10
+ expect(Addic7ed::ShowList.url_segment_for("Shameless.US")).to eq "Shameless_(US)"
11
+ expect(Addic7ed::ShowList.url_segment_for("Vikings.UK")).to eq "Vikings_(UK)"
12
12
  end
13
13
 
14
- it "detects country code even in lowercase" do
15
- expect(Addic7ed::ShowList.find("shameless.us")).to eq "Shameless_(US)"
14
+ it "is case-insensitive" do
15
+ expect(Addic7ed::ShowList.url_segment_for("shameless.us")).to eq "Shameless_(US)"
16
16
  end
17
17
 
18
- it "sets production year between parenthesis" do
19
- expect(Addic7ed::ShowList.find("Vikings.2013")).to eq "Vikings_(2013)"
18
+ it "wraps production year with parenthesis" do
19
+ expect(Addic7ed::ShowList.url_segment_for("Vikings.2013")).to eq "Vikings_(2013)"
20
20
  end
21
21
 
22
22
  it "handles when both country code and production year are present" do
23
- expect(Addic7ed::ShowList.find("Legacy.2013.UK")).to eq "Legacy_(2013)_(UK)"
23
+ expect(Addic7ed::ShowList.url_segment_for("Legacy.2013.UK")).to eq "Legacy_(2013)_(UK)"
24
24
  end
25
25
 
26
26
  it "handles when show name contains a quote" do
27
- expect(Addic7ed::ShowList.find("Grey's Anatomy")).to eq "Grey's_Anatomy"
27
+ expect(Addic7ed::ShowList.url_segment_for("Greys.Anatomy")).to eq "Grey's_Anatomy"
28
28
  end
29
29
 
30
30
  it "raises a ShowNotFound error when no matching show is found" do
31
- expect{Addic7ed::ShowList.find("Not an existing show")}.to raise_error Addic7ed::ShowNotFound
31
+ expect{Addic7ed::ShowList.url_segment_for("Not.an.existing.show")}.to raise_error Addic7ed::ShowNotFound
32
32
  end
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addic7ed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Baudino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-07 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec