thetvdb_mapper 0.0.2 → 0.0.3

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: ebe37c00f3c228440174f44a7116b34e511c15c5
4
- data.tar.gz: f28788316945638ff5788bc7ab177fad360a99d6
3
+ metadata.gz: df92a0026f71306f5581b42f4229459c664526f5
4
+ data.tar.gz: 5de89ef49942d7cfdb76385d0169edf6bb98ac20
5
5
  SHA512:
6
- metadata.gz: be570ebd08931b688b006150aaa88080ce7ff57bcf74c5bb0da7b6c4b0ebc48ed1d4ed017af73b57535dba5887f5c705b523b97c155bbedf5b4ade87afdaf85a
7
- data.tar.gz: c0decaf79aa02a7657cffc7b58565af84a0254d2b15f9aa7873c7b763327ddbdddf29d9c4668d927c05cd3766d0377465a209241b210cf7dabda03c5ccee0383
6
+ metadata.gz: 55a049dfa7a7fd87bad41192f413eac9c25b285ab035e30ce092fd740d558580faab4b696a333c17c4ee9746ffd9b7e9ed141f432ce161f843a7f344e904de38
7
+ data.tar.gz: 8dc7e5deefb4b41b6f2f90eace3b295c4a3779281c0598e1574f4f4fb10b0ad1a369487e3a02c357da74f158a0f42fc9e5a27fba01e11aca02db93e4a99503a7
data/README.md CHANGED
@@ -22,6 +22,14 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install thetvdb_mapper
24
24
 
25
+ ## Configuration
26
+
27
+ ```ruby
28
+ ThetvdbApi::Configuration.configure do |config|
29
+ config.api_key = '......'
30
+ end
31
+ ```
32
+
25
33
  ## Usage
26
34
 
27
35
  ```ruby
@@ -4,10 +4,14 @@ class ThetvdbMapper::Actors < ThetvdbMapper::Base
4
4
  end
5
5
 
6
6
  def map(data)
7
- ThetvdbMapper::Mapping::Actor.map(data)
7
+ mapping_object(data).map
8
8
  end
9
9
 
10
10
  def inspect
11
11
  "<ThetvdbMapper::Actors data=#{data.to_s} >"
12
12
  end
13
+
14
+ def mapping_object(data)
15
+ ThetvdbMapper::Mapping::Actor.new(data)
16
+ end
13
17
  end
@@ -4,10 +4,14 @@ class ThetvdbMapper::Banners < ThetvdbMapper::Base
4
4
  end
5
5
 
6
6
  def map(data)
7
- ThetvdbMapper::Mapping::Banner.map(data)
7
+ mapping_object(data).map
8
8
  end
9
9
 
10
10
  def inspect
11
11
  "<ThetvdbMapper::Banners data=#{data.to_s} >"
12
12
  end
13
+
14
+ def mapping_object(data)
15
+ ThetvdbMapper::Mapping::Banner.new(data)
16
+ end
13
17
  end
@@ -1,9 +1,13 @@
1
1
  class ThetvdbMapper::Episode < ThetvdbMapper::Base
2
2
  def data
3
- @data ||= ThetvdbMapper::Mapping::Episode.map(fetcher.episode(id).body)
3
+ @data ||= mapping_object(fetcher.episode(id).body).map
4
4
  end
5
5
 
6
6
  def inspect
7
7
  "<ThetvdbMapper::Episode data=#{data.to_s} >"
8
8
  end
9
+
10
+ def mapping_object(data)
11
+ ThetvdbMapper::Mapping::Episode.new(data)
12
+ end
9
13
  end
@@ -4,7 +4,7 @@ class ThetvdbMapper::FullSeries < ThetvdbMapper::Base
4
4
  end
5
5
 
6
6
  def series
7
- ThetvdbMapper::Mapping::Series.map(fetcher.full_series(id).body['Series'])
7
+ mapping_series_object(fetcher.full_series(id).body['Series']).map
8
8
  end
9
9
 
10
10
  def episodes
@@ -12,7 +12,7 @@ class ThetvdbMapper::FullSeries < ThetvdbMapper::Base
12
12
  end
13
13
 
14
14
  def map_episode(data)
15
- ThetvdbMapper::Mapping::Episode.map(data)
15
+ mapping_episode_object(data).map
16
16
  end
17
17
 
18
18
  def actors
@@ -20,7 +20,7 @@ class ThetvdbMapper::FullSeries < ThetvdbMapper::Base
20
20
  end
21
21
 
22
22
  def map_actor(data)
23
- ThetvdbMapper::Mapping::Actor.map(data)
23
+ mapping_actor_object(data).map
24
24
  end
25
25
 
26
26
  def banners
@@ -28,7 +28,23 @@ class ThetvdbMapper::FullSeries < ThetvdbMapper::Base
28
28
  end
29
29
 
30
30
  def map_banner(data)
31
- ThetvdbMapper::Mapping::Banner.map(data)
31
+ mapping_banner_object(data).map
32
+ end
33
+
34
+ def mapping_series_object(data)
35
+ ThetvdbMapper::Mapping::Series.new(data)
36
+ end
37
+
38
+ def mapping_episode_object(data)
39
+ ThetvdbMapper::Mapping::Episode.new(data)
40
+ end
41
+
42
+ def mapping_actor_object(data)
43
+ ThetvdbMapper::Mapping::Actor.new(data)
44
+ end
45
+
46
+ def mapping_banner_object(data)
47
+ ThetvdbMapper::Mapping::Banner.new(data)
32
48
  end
33
49
 
34
50
  def inspect
@@ -1,5 +1,5 @@
1
1
  class ThetvdbMapper::Mapping::Actor < ThetvdbMapper::Mapping::Base
2
- def self.rules
2
+ def rules
3
3
  {
4
4
  'id' => :id,
5
5
  'Image' => :image_path,
@@ -1,5 +1,5 @@
1
1
  class ThetvdbMapper::Mapping::Banner < ThetvdbMapper::Mapping::Base
2
- def self.rules
2
+ def rules
3
3
  {
4
4
  'id' => :id,
5
5
  'BannerPath' => :path,
@@ -1,17 +1,27 @@
1
1
  class ThetvdbMapper::Mapping::Base
2
- def self.map(data)
2
+ attr_reader :data
3
+
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def map
3
9
  rules.each do |before, after|
4
10
  data[after] = data.delete(before)
5
11
  end
6
12
 
7
- if respond_to?(:convert)
8
- data = convert(data)
9
- end
13
+ convert.reject{ |key, _| key.is_a?(String) }
14
+ end
15
+
16
+ def convert
17
+ data
18
+ end
10
19
 
11
- data.reject{ |key, _| key.is_a?(String) }
20
+ def convert_to_list(data)
21
+ list_mapping_object(data).map
12
22
  end
13
23
 
14
- def self.convert_to_list(data)
15
- ThetvdbMapper::Mapping::StringList.map(data)
24
+ def list_mapping_object(data)
25
+ ThetvdbMapper::Mapping::StringList.new(data)
16
26
  end
17
27
  end
@@ -1,5 +1,5 @@
1
1
  class ThetvdbMapper::Mapping::Episode < ThetvdbMapper::Mapping::Base
2
- def self.rules
2
+ def rules
3
3
  {
4
4
  'id' => :id,
5
5
  'Combined_episodenumber' => :combined_episode_number,
@@ -34,7 +34,7 @@ class ThetvdbMapper::Mapping::Episode < ThetvdbMapper::Mapping::Base
34
34
  }
35
35
  end
36
36
 
37
- def self.convert(data)
37
+ def convert
38
38
  data.merge({
39
39
  director: convert_to_list(data[:director]),
40
40
  guest_stars: convert_to_list(data[:guest_stars]),
@@ -1,5 +1,5 @@
1
1
  class ThetvdbMapper::Mapping::Series < ThetvdbMapper::Mapping::Base
2
- def self.rules
2
+ def rules
3
3
  {
4
4
  'id' => :id,
5
5
  'Airs_DayOfWeek' => :airs_day_of_week,
@@ -27,7 +27,7 @@ class ThetvdbMapper::Mapping::Series < ThetvdbMapper::Mapping::Base
27
27
  }
28
28
  end
29
29
 
30
- def self.convert(data)
30
+ def convert
31
31
  data.merge({
32
32
  genres: convert_to_list(data[:genres]),
33
33
  last_updated_at: Time.at(data[:last_updated_at].to_i)
@@ -1,5 +1,5 @@
1
- class ThetvdbMapper::Mapping::StringList
2
- def self.map(data)
1
+ class ThetvdbMapper::Mapping::StringList < ThetvdbMapper::Mapping::Base
2
+ def map
3
3
  data.to_s.split('|').reject{ |element| element.empty? }
4
4
  end
5
5
  end
@@ -1,6 +1,10 @@
1
1
  class ThetvdbMapper::Series < ThetvdbMapper::Base
2
2
  def data
3
- @data ||= ThetvdbMapper::Mapping::Series.map(fetcher.series(id).body)
3
+ @data ||= mapping_object(fetcher.series(id).body).map
4
+ end
5
+
6
+ def mapping_object(data)
7
+ ThetvdbMapper::Mapping::Series.new(data)
4
8
  end
5
9
 
6
10
  def inspect
@@ -1,3 +1,3 @@
1
1
  module ThetvdbMapper
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,31 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ThetvdbMapper::Mapping::Actor do
4
- let(:klass) { ThetvdbMapper::Mapping::Actor }
4
+ let(:model) { ThetvdbMapper::Mapping::Actor.new({}) }
5
5
 
6
- describe '#map' do
6
+ describe '.map' do
7
7
  it 'should return specific keys' do
8
- klass.map({}).keys.sort.should == [:id, :image_path, :name, :role, :sort_order].sort
8
+ model.map.keys.sort.should == [:id, :image_path, :name, :role, :sort_order].sort
9
9
  end
10
10
 
11
11
  it 'should map id' do
12
- klass.map('id' => 1234)[:id].should == 1234
12
+ model.stub(:data).and_return('id' => 1234)
13
+ model.map[:id].should == 1234
13
14
  end
14
15
 
15
16
  it 'should map Image' do
16
- klass.map('Image' => 'test')[:image_path].should == 'test'
17
+ model.stub(:data).and_return('Image' => 'test')
18
+ model.map[:image_path].should == 'test'
17
19
  end
18
20
 
19
21
  it 'should map Name' do
20
- klass.map('Name' => 'test')[:name].should == 'test'
22
+ model.stub(:data).and_return('Name' => 'test')
23
+ model.map[:name].should == 'test'
21
24
  end
22
25
 
23
26
  it 'should map Role' do
24
- klass.map('Role' => 'test')[:role].should == 'test'
27
+ model.stub(:data).and_return('Role' => 'test')
28
+ model.map[:role].should == 'test'
25
29
  end
26
30
 
27
31
  it 'should map SortOrder' do
28
- klass.map('SortOrder' => 1)[:sort_order].should == 1
32
+ model.stub(:data).and_return('SortOrder' => 1)
33
+ model.map[:sort_order].should == 1
29
34
  end
30
35
  end
31
36
  end
@@ -1,60 +1,72 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ThetvdbMapper::Mapping::Banner do
4
- let(:klass) { ThetvdbMapper::Mapping::Banner }
4
+ let(:model) { ThetvdbMapper::Mapping::Banner.new({}) }
5
5
 
6
6
  describe '#map' do
7
7
  it 'should return specific keys' do
8
- klass.map({}).keys.sort.should == [:path, :thumbnail_path, :vignette_path, :type, :type2, :language, :season,
8
+ model.map.keys.sort.should == [:path, :thumbnail_path, :vignette_path, :type, :type2, :language, :season,
9
9
  :rating, :rating_count, :series_name, :colors, :id].sort
10
10
  end
11
11
 
12
12
  it 'should map id' do
13
- klass.map('id' => '1')[:id].should == '1'
13
+ model.stub(:data).and_return('id' => '1')
14
+ model.map[:id].should == '1'
14
15
  end
15
16
 
16
17
  it 'should map BannerPath' do
17
- klass.map('BannerPath' => 'test')[:path].should == 'test'
18
+ model.stub(:data).and_return('BannerPath' => 'test')
19
+ model.map[:path].should == 'test'
18
20
  end
19
21
 
20
22
  it 'should map ThumbnailPath' do
21
- klass.map('ThumbnailPath' => 'test')[:thumbnail_path].should == 'test'
23
+ model.stub(:data).and_return('ThumbnailPath' => 'test')
24
+ model.map[:thumbnail_path].should == 'test'
22
25
  end
23
26
 
24
27
  it 'should map VignettePath' do
25
- klass.map('VignettePath' => 'test')[:vignette_path].should == 'test'
28
+ model.stub(:data).and_return('VignettePath' => 'test')
29
+ model.map[:vignette_path].should == 'test'
26
30
  end
27
31
 
28
32
  it 'should map BannerType' do
29
- klass.map('BannerType' => 'test')[:type].should == 'test'
33
+ model.stub(:data).and_return('BannerType' => 'test')
34
+ model.map[:type].should == 'test'
30
35
  end
31
36
 
32
37
  it 'should map BannerType2' do
33
- klass.map('BannerType2' => 'test')[:type2].should == 'test'
38
+ model.stub(:data).and_return('BannerType2' => 'test')
39
+ model.map[:type2].should == 'test'
34
40
  end
35
41
 
36
42
  it 'should map Language' do
37
- klass.map('Language' => 'test')[:language].should == 'test'
43
+ model.stub(:data).and_return('Language' => 'test')
44
+ model.map[:language].should == 'test'
38
45
  end
39
46
 
40
47
  it 'should map Season' do
41
- klass.map('Season' => 'test')[:season].should == 'test'
48
+ model.stub(:data).and_return('Season' => 'test')
49
+ model.map[:season].should == 'test'
42
50
  end
43
51
 
44
52
  it 'should map Rating' do
45
- klass.map('Rating' => 'test')[:rating].should == 'test'
53
+ model.stub(:data).and_return('Rating' => 'test')
54
+ model.map[:rating].should == 'test'
46
55
  end
47
56
 
48
57
  it 'should map RatingCount' do
49
- klass.map('RatingCount' => 'test')[:rating_count].should == 'test'
58
+ model.stub(:data).and_return('RatingCount' => 'test')
59
+ model.map[:rating_count].should == 'test'
50
60
  end
51
61
 
52
62
  it 'should map SeriesName' do
53
- klass.map('SeriesName' => 'test')[:series_name].should == 'test'
63
+ model.stub(:data).and_return('SeriesName' => 'test')
64
+ model.map[:series_name].should == 'test'
54
65
  end
55
66
 
56
67
  it 'should map Colors' do
57
- klass.map('Colors' => 'test')[:colors].should == 'test'
68
+ model.stub(:data).and_return('Colors' => 'test')
69
+ model.map[:colors].should == 'test'
58
70
  end
59
71
  end
60
72
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ThetvdbMapper::Mapping::Episode do
4
- let(:klass) { ThetvdbMapper::Mapping::Episode }
4
+ let(:model) { ThetvdbMapper::Mapping::Episode.new({}) }
5
5
 
6
6
  describe '#map' do
7
7
  it 'should return specific keys' do
8
- klass.map({}).keys.sort.should == [:id, :combined_episode_number, :combined_season, :dvd_episode_number,
8
+ model.map.keys.sort.should == [:id, :combined_episode_number, :combined_season, :dvd_episode_number,
9
9
  :dvd_season, :director, :ep_img_flag, :name, :number, :first_aired, :guest_stars, :imdb_id, :language,
10
10
  :overview, :production_code, :rating, :rating_count, :season, :writer, :absolute_number, :airs_after_season,
11
11
  :airs_before_episode, :airs_before_season, :filename_path, :last_updated_at, :season_id, :series_id,
@@ -13,123 +13,153 @@ describe ThetvdbMapper::Mapping::Episode do
13
13
  end
14
14
 
15
15
  it 'should map id' do
16
- klass.map('id' => 1234)[:id].should == 1234
16
+ model.stub(:data).and_return('id' => 1234)
17
+ model.map[:id].should == 1234
17
18
  end
18
19
 
19
20
  it 'should map Combined_episodenumber' do
20
- klass.map('Combined_episodenumber' => 1234)[:combined_episode_number].should == 1234
21
+ model.stub(:data).and_return('Combined_episodenumber' => 1234)
22
+ model.map[:combined_episode_number].should == 1234
21
23
  end
22
24
 
23
25
  it 'should map Combined_season' do
24
- klass.map('Combined_season' => 1234)[:combined_season].should == 1234
26
+ model.stub(:data).and_return('Combined_season' => 1234)
27
+ model.map[:combined_season].should == 1234
25
28
  end
26
29
 
27
30
  it 'should map DVD_episodenumber' do
28
- klass.map('DVD_episodenumber' => 1234)[:dvd_episode_number].should == 1234
31
+ model.stub(:data).and_return('DVD_episodenumber' => 1234)
32
+ model.map[:dvd_episode_number].should == 1234
29
33
  end
30
34
 
31
35
  it 'should map DVD_season' do
32
- klass.map('DVD_season' => 1234)[:dvd_season].should == 1234
36
+ model.stub(:data).and_return('DVD_season' => 1234)
37
+ model.map[:dvd_season].should == 1234
33
38
  end
34
39
 
35
40
  it 'should map Director' do
36
- klass.map('Director' => '|test|')[:director].should == ['test']
41
+ model.stub(:data).and_return('Director' => '|test|')
42
+ model.map[:director].should == ['test']
37
43
  end
38
44
 
39
45
  it 'should map EpImgFlag' do
40
- klass.map('EpImgFlag' => 1234)[:ep_img_flag].should == 1234
46
+ model.stub(:data).and_return('EpImgFlag' => 1234)
47
+ model.map[:ep_img_flag].should == 1234
41
48
  end
42
49
 
43
50
  it 'should map EpisodeName' do
44
- klass.map('EpisodeName' => 'test')[:name].should == 'test'
51
+ model.stub(:data).and_return('EpisodeName' => 'test')
52
+ model.map[:name].should == 'test'
45
53
  end
46
54
 
47
55
  it 'should map EpisodeNumber' do
48
- klass.map('EpisodeNumber' => 1234)[:number].should == 1234
56
+ model.stub(:data).and_return('EpisodeNumber' => 1234)
57
+ model.map[:number].should == 1234
49
58
  end
50
59
 
51
60
  it 'should map FirstAired' do
52
- klass.map('FirstAired' => 1234)[:first_aired].should == 1234
61
+ model.stub(:data).and_return('FirstAired' => 1234)
62
+ model.map[:first_aired].should == 1234
53
63
  end
54
64
 
55
65
  it 'should map GuestStars' do
56
- klass.map('GuestStars' => '|test|')[:guest_stars].should == ['test']
66
+ model.stub(:data).and_return('GuestStars' => '|test|')
67
+ model.map[:guest_stars].should == ['test']
57
68
  end
58
69
 
59
70
  it 'should map IMDB_ID' do
60
- klass.map('IMDB_ID' => 'test')[:imdb_id].should == 'test'
71
+ model.stub(:data).and_return('IMDB_ID' => 'test')
72
+ model.map[:imdb_id].should == 'test'
61
73
  end
62
74
 
63
75
  it 'should map Language' do
64
- klass.map('Language' => 'test')[:language].should == 'test'
76
+ model.stub(:data).and_return('Language' => 'test')
77
+ model.map[:language].should == 'test'
65
78
  end
66
79
 
67
80
  it 'should map Overview' do
68
- klass.map('Overview' => 'test')[:overview].should == 'test'
81
+ model.stub(:data).and_return('Overview' => 'test')
82
+ model.map[:overview].should == 'test'
69
83
  end
70
84
 
71
85
  it 'should map ProductionCode' do
72
- klass.map('ProductionCode' => 'test')[:production_code].should == 'test'
86
+ model.stub(:data).and_return('ProductionCode' => 'test')
87
+ model.map[:production_code].should == 'test'
73
88
  end
74
89
 
75
90
  it 'should map Rating' do
76
- klass.map('Rating' => '1.0')[:rating].should == '1.0'
91
+ model.stub(:data).and_return('Rating' => '1.0')
92
+ model.map[:rating].should == '1.0'
77
93
  end
78
94
 
79
95
  it 'should map RatingCount' do
80
- klass.map('RatingCount' => '1')[:rating_count].should == '1'
96
+ model.stub(:data).and_return('RatingCount' => '1')
97
+ model.map[:rating_count].should == '1'
81
98
  end
82
99
 
83
100
  it 'should map SeasonNumber' do
84
- klass.map('SeasonNumber' => '1')[:season].should == '1'
101
+ model.stub(:data).and_return('SeasonNumber' => '1')
102
+ model.map[:season].should == '1'
85
103
  end
86
104
 
87
105
  it 'should map Writer' do
88
- klass.map('Writer' => '|test|')[:writer].should == ['test']
106
+ model.stub(:data).and_return('Writer' => '|test|')
107
+ model.map[:writer].should == ['test']
89
108
  end
90
109
 
91
110
  it 'should map absolute_number' do
92
- klass.map('absolute_number' => '1')[:absolute_number].should == '1'
111
+ model.stub(:data).and_return('absolute_number' => '1')
112
+ model.map[:absolute_number].should == '1'
93
113
  end
94
114
 
95
115
  it 'should map airsafter_season' do
96
- klass.map('airsafter_season' => '1')[:airs_after_season].should == '1'
116
+ model.stub(:data).and_return('airsafter_season' => '1')
117
+ model.map[:airs_after_season].should == '1'
97
118
  end
98
119
 
99
120
  it 'should map airsbefore_episode' do
100
- klass.map('airsbefore_episode' => '1')[:airs_before_episode].should == '1'
121
+ model.stub(:data).and_return('airsbefore_episode' => '1')
122
+ model.map[:airs_before_episode].should == '1'
101
123
  end
102
124
 
103
125
  it 'should map airsbefore_season' do
104
- klass.map('airsbefore_season' => '1')[:airs_before_season].should == '1'
126
+ model.stub(:data).and_return('airsbefore_season' => '1')
127
+ model.map[:airs_before_season].should == '1'
105
128
  end
106
129
 
107
130
  it 'should map filename' do
108
- klass.map('filename' => 'test')[:filename_path].should == 'test'
131
+ model.stub(:data).and_return('filename' => 'test')
132
+ model.map[:filename_path].should == 'test'
109
133
  end
110
134
 
111
135
  it 'should map lastupdated' do
112
- klass.map('lastupdated' => '1234')[:last_updated_at].should == Time.at(1234)
136
+ model.stub(:data).and_return('lastupdated' => '1234')
137
+ model.map[:last_updated_at].should == Time.at(1234)
113
138
  end
114
139
 
115
140
  it 'should map seasonid' do
116
- klass.map('seasonid' => '1')[:season_id].should == '1'
141
+ model.stub(:data).and_return('seasonid' => '1')
142
+ model.map[:season_id].should == '1'
117
143
  end
118
144
 
119
145
  it 'should map seriesid' do
120
- klass.map('seriesid' => '1')[:series_id].should == '1'
146
+ model.stub(:data).and_return('seriesid' => '1')
147
+ model.map[:series_id].should == '1'
121
148
  end
122
149
 
123
150
  it 'should map thumb_added' do
124
- klass.map('thumb_added' => 'test')[:thumbnail_added_at].should == 'test'
151
+ model.stub(:data).and_return('thumb_added' => 'test')
152
+ model.map[:thumbnail_added_at].should == 'test'
125
153
  end
126
154
 
127
155
  it 'should map thumb_height' do
128
- klass.map('thumb_height' => 'test')[:thumbnail_height].should == 'test'
156
+ model.stub(:data).and_return('thumb_height' => 'test')
157
+ model.map[:thumbnail_height].should == 'test'
129
158
  end
130
159
 
131
160
  it 'should map thumb_width' do
132
- klass.map('thumb_width' => 'test')[:thumbnail_width].should == 'test'
161
+ model.stub(:data).and_return('thumb_width' => 'test')
162
+ model.map[:thumbnail_width].should == 'test'
133
163
  end
134
164
  end
135
165
  end