filmaffinity 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +227 -0
- data/README.md +9 -0
- data/filmaffinity.gemspec +3 -3
- data/lib/constants/constants.rb +41 -43
- data/lib/filmaffinity/json-movie-parser.rb +3 -3
- data/lib/filmaffinity/json-movies-parser.rb +3 -4
- data/lib/filmaffinity/movie.rb +23 -30
- data/lib/filmaffinity/poster-manager.rb +3 -4
- data/lib/filmaffinity/search.rb +3 -4
- data/lib/filmaffinity/top.rb +14 -17
- data/spec/filmaffinity/json-movie-parser_spec.rb +1 -5
- data/spec/filmaffinity/json-movies-parser_spec.rb +6 -10
- data/spec/filmaffinity/movie_spec.rb +23 -23
- data/spec/filmaffinity/search_spec.rb +3 -7
- data/spec/filmaffinity/top_spec.rb +69 -73
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29ef0361d9518662bb80c94ec7935ec0706b3874
|
4
|
+
data.tar.gz: 17684ee3bf5f24ed46766a0e8539cbfde0812316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61606a76a4d418ffe81b087504df61332423de8759ca12fbf5b580bc1f70fdb98a1b952e1d98b687e5d7f92072cd1414152cc0587032c693eb9621307be5a86b
|
7
|
+
data.tar.gz: d4a64c23d3c57b8982ed609931ed9f939c063dfdfac6c388fa9441317ee45c7cd37272b4858560e83855c6f73aa23375cfcb072a1122032e9caa65c4a4315f58
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-04-19 12:48:01 +0200 using RuboCop version 0.39.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: AlignWith, SupportedStyles.
|
12
|
+
# SupportedStyles: either, start_of_block, start_of_line
|
13
|
+
Lint/BlockAlignment:
|
14
|
+
Exclude:
|
15
|
+
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
# Configuration parameters: IgnoreEmptyBlocks.
|
20
|
+
Lint/UnusedBlockArgument:
|
21
|
+
Exclude:
|
22
|
+
# - 'lib/filmaffinity/top.rb'
|
23
|
+
|
24
|
+
# Offense count: 35
|
25
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
26
|
+
# URISchemes: http, https
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 134
|
29
|
+
|
30
|
+
# Offense count: 2
|
31
|
+
# Configuration parameters: CountComments.
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 50
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
# Cop supports --auto-correct.
|
37
|
+
Performance/StringReplacement:
|
38
|
+
Exclude:
|
39
|
+
# - 'lib/filmaffinity/movie.rb'
|
40
|
+
|
41
|
+
# Offense count: 8
|
42
|
+
# Cop supports --auto-correct.
|
43
|
+
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
44
|
+
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
45
|
+
Style/AlignHash:
|
46
|
+
Exclude:
|
47
|
+
|
48
|
+
|
49
|
+
# Offense count: 1
|
50
|
+
# Cop supports --auto-correct.
|
51
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
52
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
53
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
54
|
+
# FunctionalMethods: let, let!, subject, watch
|
55
|
+
# IgnoredMethods: lambda, proc, it
|
56
|
+
Style/BlockDelimiters:
|
57
|
+
Exclude:
|
58
|
+
|
59
|
+
|
60
|
+
# Offense count: 9
|
61
|
+
Style/Documentation:
|
62
|
+
Exclude:
|
63
|
+
- 'spec/**/*'
|
64
|
+
- 'test/**/*'
|
65
|
+
- 'lib/constants/constants.rb'
|
66
|
+
- 'lib/filmaffinity.rb'
|
67
|
+
- 'lib/filmaffinity/configuration.rb'
|
68
|
+
- 'lib/filmaffinity/json-movie-parser.rb'
|
69
|
+
- 'lib/filmaffinity/json-movies-parser.rb'
|
70
|
+
- 'lib/filmaffinity/movie.rb'
|
71
|
+
- 'lib/filmaffinity/poster-manager.rb'
|
72
|
+
- 'lib/filmaffinity/search.rb'
|
73
|
+
- 'lib/filmaffinity/top.rb'
|
74
|
+
|
75
|
+
# Offense count: 2
|
76
|
+
# Cop supports --auto-correct.
|
77
|
+
# Configuration parameters: AllowAdjacentOneLineDefs.
|
78
|
+
Style/EmptyLineBetweenDefs:
|
79
|
+
Exclude:
|
80
|
+
# - 'lib/filmaffinity/json-movie-parser.rb'
|
81
|
+
# - 'lib/filmaffinity/json-movies-parser.rb'
|
82
|
+
|
83
|
+
# Offense count: 3
|
84
|
+
# Cop supports --auto-correct.
|
85
|
+
Style/EmptyLines:
|
86
|
+
Exclude:
|
87
|
+
|
88
|
+
|
89
|
+
# Offense count: 13
|
90
|
+
# Cop supports --auto-correct.
|
91
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
92
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
93
|
+
Style/EmptyLinesAroundBlockBody:
|
94
|
+
Exclude:
|
95
|
+
|
96
|
+
|
97
|
+
# Offense count: 5
|
98
|
+
# Cop supports --auto-correct.
|
99
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
100
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
101
|
+
Style/EmptyLinesAroundClassBody:
|
102
|
+
Exclude:
|
103
|
+
|
104
|
+
|
105
|
+
# Offense count: 2
|
106
|
+
# Cop supports --auto-correct.
|
107
|
+
Style/EmptyLinesAroundMethodBody:
|
108
|
+
Exclude:
|
109
|
+
|
110
|
+
# Offense count: 2
|
111
|
+
# Cop supports --auto-correct.
|
112
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
113
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
114
|
+
Style/EmptyLinesAroundModuleBody:
|
115
|
+
Exclude:
|
116
|
+
|
117
|
+
# Offense count: 1
|
118
|
+
# Cop supports --auto-correct.
|
119
|
+
Style/EmptyLiteral:
|
120
|
+
Exclude:
|
121
|
+
|
122
|
+
|
123
|
+
# Offense count: 6
|
124
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
125
|
+
Style/FileName:
|
126
|
+
Exclude:
|
127
|
+
#CAREFUL FileName Bug!
|
128
|
+
- 'lib/filmaffinity/json-movie-parser.rb'
|
129
|
+
- 'lib/filmaffinity/json-movies-parser.rb'
|
130
|
+
- 'lib/filmaffinity/poster-manager.rb'
|
131
|
+
- 'spec/filmaffinity/json-movie-parser_spec.rb'
|
132
|
+
- 'spec/filmaffinity/json-movies-parser_spec.rb'
|
133
|
+
- 'spec/filmaffinity/matchers/include-movie.rb'
|
134
|
+
|
135
|
+
# Offense count: 59
|
136
|
+
# Cop supports --auto-correct.
|
137
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
138
|
+
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
139
|
+
Style/HashSyntax:
|
140
|
+
Enabled: enable
|
141
|
+
|
142
|
+
# Offense count: 3
|
143
|
+
# Cop supports --auto-correct.
|
144
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
145
|
+
# SupportedStyles: normal, rails
|
146
|
+
Style/IndentationConsistency:
|
147
|
+
Exclude:
|
148
|
+
# - 'lib/filmaffinity/top.rb'
|
149
|
+
# - 'spec/filmaffinity/movie_spec.rb'
|
150
|
+
|
151
|
+
# Offense count: 1
|
152
|
+
# Cop supports --auto-correct.
|
153
|
+
Style/LeadingCommentSpace:
|
154
|
+
Exclude:
|
155
|
+
# - 'spec/filmaffinity/search_spec.rb'
|
156
|
+
|
157
|
+
# Offense count: 11
|
158
|
+
# Cop supports --auto-correct.
|
159
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
160
|
+
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
|
161
|
+
Style/MethodDefParentheses:
|
162
|
+
Enabled: true
|
163
|
+
|
164
|
+
# Offense count: 29
|
165
|
+
# Cop supports --auto-correct.
|
166
|
+
Style/NumericLiterals:
|
167
|
+
Enabled: true
|
168
|
+
|
169
|
+
# Offense count: 3
|
170
|
+
# Cop supports --auto-correct.
|
171
|
+
Style/RedundantParentheses:
|
172
|
+
Exclude:
|
173
|
+
|
174
|
+
|
175
|
+
# Offense count: 6
|
176
|
+
# Cop supports --auto-correct.
|
177
|
+
Style/RedundantSelf:
|
178
|
+
Exclude:
|
179
|
+
|
180
|
+
|
181
|
+
# Offense count: 4
|
182
|
+
# Cop supports --auto-correct.
|
183
|
+
Style/SpaceAfterColon:
|
184
|
+
Exclude:
|
185
|
+
|
186
|
+
|
187
|
+
# Offense count: 9
|
188
|
+
# Cop supports --auto-correct.
|
189
|
+
Style/SpaceAfterComma:
|
190
|
+
Exclude:
|
191
|
+
|
192
|
+
|
193
|
+
# Offense count: 1
|
194
|
+
# Cop supports --auto-correct.
|
195
|
+
# Configuration parameters: AllowForAlignment.
|
196
|
+
Style/SpaceAroundOperators:
|
197
|
+
Exclude:
|
198
|
+
|
199
|
+
|
200
|
+
# Offense count: 3
|
201
|
+
# Cop supports --auto-correct.
|
202
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
203
|
+
# SupportedStyles: space, no_space
|
204
|
+
Style/SpaceInsideHashLiteralBraces:
|
205
|
+
Enabled: false
|
206
|
+
|
207
|
+
# Offense count: 209
|
208
|
+
# Cop supports --auto-correct.
|
209
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
210
|
+
# SupportedStyles: single_quotes, double_quotes
|
211
|
+
Style/StringLiterals:
|
212
|
+
Enabled: false
|
213
|
+
|
214
|
+
# Offense count: 1
|
215
|
+
# Cop supports --auto-correct.
|
216
|
+
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
217
|
+
# SupportedStyles: comma, consistent_comma, no_comma
|
218
|
+
Style/TrailingCommaInLiteral:
|
219
|
+
Exclude:
|
220
|
+
- 'lib/constants/constants.rb'
|
221
|
+
|
222
|
+
# Offense count: 2
|
223
|
+
# Cop supports --auto-correct.
|
224
|
+
# Configuration parameters: SupportedStyles, MinSize, WordRegex.
|
225
|
+
# SupportedStyles: percent, brackets
|
226
|
+
Style/WordArray:
|
227
|
+
EnforcedStyle: brackets
|
data/README.md
CHANGED
@@ -30,6 +30,15 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Documentation
|
32
32
|
|
33
|
+
##### FilmAffinity configuration
|
34
|
+
FilmAffinity has some configuration options, which you can configure globally before your requests. Could include an ```imgur_id``` to upload the posters on Imgur and avoid forbidden hotlinking from filmaffinity. Also you can change the ```language```, english by default.
|
35
|
+
```
|
36
|
+
FilmAffinity.configure do |config|
|
37
|
+
config.imgur_id = "Your-imgur-client-id"
|
38
|
+
config.language = "ES"
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
33
42
|
##### FilmAffinity::Search
|
34
43
|
Return an array of FilmAffinity::Movie, just containing preload ID and title.
|
35
44
|
|
data/filmaffinity.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'filmaffinity'
|
3
|
-
s.version = '0.3.
|
4
|
-
s.date = '2016-04-
|
3
|
+
s.version = '0.3.1'
|
4
|
+
s.date = '2016-04-19'
|
5
5
|
s.summary = "filmaffinity"
|
6
6
|
s.description = "Easily use Ruby or the command line to find information on Filmaffinity.com"
|
7
7
|
s.authors = ["David Santos", "Oriol Bellido"]
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.license = 'MIT'
|
15
15
|
s.add_dependency 'nokogiri', ' ~> 1.6'
|
16
16
|
s.add_dependency 'json', ' ~> 1.8'
|
17
|
-
s.add_dependency 'imgur-api','~> 0'
|
17
|
+
s.add_dependency 'imgur-api', '~> 0'
|
18
18
|
s.add_development_dependency 'rake', '~> 10.0'
|
19
19
|
s.add_development_dependency 'rspec', '~> 3.3'
|
20
20
|
end
|
data/lib/constants/constants.rb
CHANGED
@@ -1,89 +1,88 @@
|
|
1
1
|
module Constants
|
2
|
-
|
3
2
|
def self.query_params
|
4
3
|
{
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
4
|
+
genre: 'genre=%s&',
|
5
|
+
country: 'country=%s&',
|
6
|
+
from_year: 'fromyear=%i&',
|
7
|
+
to_year: 'toyear=%i&',
|
8
|
+
no_doc: 'nodoc&',
|
9
|
+
no_tv: 'notvse&',
|
11
10
|
}
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.urls
|
15
14
|
{
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
15
|
+
top: "http://www.filmaffinity.com/#{lang}/topgen.php%s",
|
16
|
+
search_by_title: "http://www.filmaffinity.com/#{lang}/search.php?stext=%s&stype=title",
|
17
|
+
movie: "http://www.filmaffinity.com/#{lang}/film%i.html"
|
19
18
|
}
|
20
19
|
end
|
21
20
|
|
22
21
|
def self.tags
|
23
22
|
{
|
24
23
|
|
25
|
-
:
|
26
|
-
|
24
|
+
title: { EN: '#main-title span',
|
25
|
+
ES: '#main-title span'
|
27
26
|
},
|
28
27
|
|
29
|
-
:
|
30
|
-
|
28
|
+
year: { EN: 'dd[itemprop="datePublished"]',
|
29
|
+
ES: 'dd[itemprop="datePublished"]'
|
31
30
|
},
|
32
31
|
|
33
|
-
:
|
34
|
-
|
32
|
+
duration: { EN: 'dd[itemprop="duration"]',
|
33
|
+
ES: 'dd[itemprop="duration"]'
|
35
34
|
},
|
36
35
|
|
37
|
-
:
|
38
|
-
|
36
|
+
country: { EN: '#country-img',
|
37
|
+
ES: '#country-img'
|
39
38
|
},
|
40
39
|
|
41
|
-
:
|
42
|
-
|
40
|
+
director: { EN: 'a[itemprop="url"]',
|
41
|
+
ES: 'a[itemprop="url"]'
|
43
42
|
},
|
44
43
|
|
45
|
-
:
|
46
|
-
|
44
|
+
music: { EN: 'dt:contains("Music")',
|
45
|
+
ES: 'dt:contains("Música")'
|
47
46
|
},
|
48
47
|
|
49
|
-
:
|
50
|
-
|
48
|
+
company: { EN: 'dt:contains("Producer")',
|
49
|
+
ES: 'dt:contains("Productora")'
|
51
50
|
},
|
52
51
|
|
53
|
-
:
|
54
|
-
|
52
|
+
script: { EN: 'dt:contains("Screenwriter")',
|
53
|
+
ES: 'dt:contains("Guión")'
|
55
54
|
},
|
56
55
|
|
57
|
-
:
|
58
|
-
|
56
|
+
photography: { EN: 'dt:contains("Cinematography")',
|
57
|
+
ES: 'dt:contains("Fotografía")'
|
59
58
|
},
|
60
59
|
|
61
|
-
:
|
62
|
-
|
60
|
+
cast: { EN: 'span[itemprop="actor"]',
|
61
|
+
ES: 'span[itemprop="actor"]'
|
63
62
|
},
|
64
63
|
|
65
|
-
:
|
66
|
-
|
64
|
+
cast_each: { EN: 'span[itemprop="name"]',
|
65
|
+
ES: 'span[itemprop="name"]'
|
67
66
|
},
|
68
67
|
|
69
|
-
:
|
70
|
-
|
68
|
+
genre: { EN: 'dt:contains("Genre")',
|
69
|
+
ES: 'dt:contains("Género")'
|
71
70
|
},
|
72
71
|
|
73
|
-
:
|
74
|
-
|
72
|
+
sinopsis: { EN: 'dd[itemprop="description"]',
|
73
|
+
ES: 'dd[itemprop="description"]'
|
75
74
|
},
|
76
75
|
|
77
|
-
:
|
78
|
-
|
76
|
+
rating: { EN: 'div[itemprop="ratingValue"]',
|
77
|
+
ES: 'div[itemprop="ratingValue"]'
|
79
78
|
},
|
80
79
|
|
81
|
-
:
|
82
|
-
|
80
|
+
poster: { EN: 'img[itemprop="image"]',
|
81
|
+
ES: 'img[itemprop="image"]'
|
83
82
|
},
|
84
83
|
|
85
|
-
:
|
86
|
-
|
84
|
+
poster_big: { EN: 'a[class="lightbox"]',
|
85
|
+
ES: 'a[class="lightbox"]'
|
87
86
|
}
|
88
87
|
|
89
88
|
}
|
@@ -97,5 +96,4 @@ module Constants
|
|
97
96
|
def self.lang
|
98
97
|
FilmAffinity.configuration.language.downcase
|
99
98
|
end
|
100
|
-
|
101
99
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
3
|
class JsonMovieParser
|
4
|
-
|
5
|
-
def to_hash movie
|
4
|
+
def to_hash(movie)
|
6
5
|
{
|
7
6
|
"title" => movie.title,
|
8
7
|
"rating" => movie.rating,
|
@@ -15,7 +14,8 @@ class JsonMovieParser
|
|
15
14
|
"sinopsis" => movie.sinopsis
|
16
15
|
}
|
17
16
|
end
|
18
|
-
|
17
|
+
|
18
|
+
def to_json(movie)
|
19
19
|
hash = to_hash movie
|
20
20
|
hash.to_json
|
21
21
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class JsonMoviesParser
|
2
|
-
|
3
|
-
def to_hashes movies
|
2
|
+
def to_hashes(movies)
|
4
3
|
hashes = []
|
5
4
|
movies.each do |movie|
|
6
5
|
hash = {
|
@@ -11,9 +10,9 @@ class JsonMoviesParser
|
|
11
10
|
end
|
12
11
|
hashes
|
13
12
|
end
|
14
|
-
|
13
|
+
|
14
|
+
def to_json(movies)
|
15
15
|
hashes = to_hashes movies
|
16
16
|
hashes.to_json
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
data/lib/filmaffinity/movie.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
1
|
module FilmAffinity
|
3
2
|
class Movie
|
4
3
|
attr_reader :id, :title
|
5
|
-
def initialize
|
4
|
+
def initialize(id, title = nil)
|
6
5
|
@id = id
|
7
6
|
@title = title if title
|
8
7
|
@json_parser = JsonMovieParser.new
|
@@ -10,7 +9,7 @@ module FilmAffinity
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def document_html
|
13
|
-
@document_html ||= Nokogiri::HTML(
|
12
|
+
@document_html ||= Nokogiri::HTML(generate_html)
|
14
13
|
end
|
15
14
|
|
16
15
|
def generate_html
|
@@ -18,85 +17,79 @@ module FilmAffinity
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def title
|
21
|
-
@title ||= document_html.at(Constants.tag(:title)).content.strip
|
20
|
+
@title ||= document_html.at(Constants.tag(:title)).content.strip rescue nil
|
22
21
|
end
|
23
22
|
|
24
23
|
def year
|
25
|
-
document_html.at(Constants.tag(:year)).content[/\d+/].to_i
|
24
|
+
document_html.at(Constants.tag(:year)).content[/\d+/].to_i rescue nil
|
26
25
|
end
|
27
26
|
|
28
27
|
def duration
|
29
|
-
document_html.at(Constants.tag(:duration)).content[/\d+/].to_i
|
28
|
+
document_html.at(Constants.tag(:duration)).content[/\d+/].to_i rescue nil
|
30
29
|
end
|
31
30
|
|
32
31
|
def country
|
33
|
-
raw_country = document_html.at(Constants.tag(:country)).next_sibling.content
|
34
|
-
raw_country.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
|
32
|
+
raw_country = document_html.at(Constants.tag(:country)).next_sibling.content rescue nil
|
33
|
+
raw_country.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '') if raw_country
|
35
34
|
end
|
36
35
|
|
37
36
|
def director
|
38
|
-
raw_director = document_html.at(Constants.tag(:director)).content
|
39
|
-
raw_director.strip
|
37
|
+
raw_director = document_html.at(Constants.tag(:director)).content rescue nil
|
38
|
+
raw_director.strip if raw_director
|
40
39
|
end
|
41
40
|
|
42
41
|
def music
|
43
|
-
document_html.at(Constants.tag(:music)).next_sibling.next_sibling.content
|
42
|
+
document_html.at(Constants.tag(:music)).next_sibling.next_sibling.content rescue nil
|
44
43
|
end
|
45
44
|
|
46
45
|
def company
|
47
|
-
document_html.at(Constants.tag(:company)).next_sibling.next_sibling.content
|
46
|
+
document_html.at(Constants.tag(:company)).next_sibling.next_sibling.content rescue nil
|
48
47
|
end
|
49
48
|
|
50
49
|
def script
|
51
|
-
document_html.at(Constants.tag(:script)).next_sibling.next_sibling.content
|
50
|
+
document_html.at(Constants.tag(:script)).next_sibling.next_sibling.content rescue nil
|
52
51
|
end
|
53
52
|
|
54
53
|
def photography
|
55
|
-
document_html.at(
|
54
|
+
document_html.at(Constants.tag(:photography)).next_sibling.next_sibling.content rescue nil
|
56
55
|
end
|
57
56
|
|
58
57
|
def cast
|
59
58
|
actors = []
|
60
|
-
node = document_html.search(
|
59
|
+
node = document_html.search(Constants.tag(:cast)) rescue []
|
61
60
|
node.each do |actor|
|
62
|
-
actors << actor.at(
|
61
|
+
actors << actor.at(Constants.tag(:cast_each)).content.strip
|
63
62
|
end
|
64
63
|
actors
|
65
64
|
end
|
66
65
|
|
67
66
|
def genres
|
68
67
|
genres = []
|
69
|
-
node = document_html.at(Constants.tag(:genre)).next_sibling.next_sibling
|
68
|
+
node = document_html.at(Constants.tag(:genre)).next_sibling.next_sibling rescue []
|
70
69
|
raw_genres = node.search("a")
|
71
70
|
raw_genres.each do |raw_genre|
|
72
71
|
genres << raw_genre.content.strip
|
73
72
|
end
|
74
73
|
genres
|
75
|
-
|
76
74
|
end
|
77
75
|
|
78
76
|
def sinopsis
|
79
|
-
document_html.at(Constants.tag(:sinopsis)).content
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
def prizes
|
84
|
-
|
77
|
+
document_html.at(Constants.tag(:sinopsis)).content rescue nil
|
85
78
|
end
|
86
79
|
|
87
80
|
def rating
|
88
|
-
raw_rating = document_html.at(Constants.tag(:rating)).content.strip
|
89
|
-
raw_rating.
|
81
|
+
raw_rating = document_html.at(Constants.tag(:rating)).content.strip rescue nil
|
82
|
+
raw_rating.tr(",", ".").to_f if raw_rating
|
90
83
|
end
|
91
84
|
|
92
85
|
def poster
|
93
|
-
poster_url = document_html.at(Constants.tag(:poster))["src"]
|
94
|
-
@poster_manager.load_poster(poster_url)
|
86
|
+
poster_url = document_html.at(Constants.tag(:poster))["src"] rescue nil
|
87
|
+
@poster_manager.load_poster(poster_url) if poster_url
|
95
88
|
end
|
96
89
|
|
97
90
|
def poster_big
|
98
|
-
poster_url = document_html.at(Constants.tag(:poster_big))["href"]
|
99
|
-
@poster_manager.load_poster(poster_url)
|
91
|
+
poster_url = document_html.at(Constants.tag(:poster_big))["href"] rescue nil
|
92
|
+
@poster_manager.load_poster(poster_url) if poster_url
|
100
93
|
end
|
101
94
|
|
102
95
|
def to_json
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "imgur"
|
3
3
|
|
4
|
-
|
5
4
|
class PosterManager
|
6
5
|
def load_poster(posterurl)
|
7
6
|
return posterurl unless FilmAffinity.configuration.imgur_id
|
@@ -19,11 +18,11 @@ class PosterManager
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def save_img_locally(posterurl)
|
22
|
-
open(posterurl)
|
23
|
-
File.open(@dir,"wb") do |file|
|
21
|
+
open(posterurl) do |f|
|
22
|
+
File.open(@dir, "wb") do |file|
|
24
23
|
file.puts f.read
|
25
24
|
end
|
26
|
-
|
25
|
+
end
|
27
26
|
end
|
28
27
|
|
29
28
|
def construct_name
|
data/lib/filmaffinity/search.rb
CHANGED
@@ -2,7 +2,7 @@ require "cgi"
|
|
2
2
|
|
3
3
|
module FilmAffinity
|
4
4
|
class Search
|
5
|
-
def initialize
|
5
|
+
def initialize(query)
|
6
6
|
@query = query
|
7
7
|
@json_parser = JsonMoviesParser.new
|
8
8
|
end
|
@@ -16,7 +16,7 @@ module FilmAffinity
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def document_html
|
19
|
-
@document_html ||= Nokogiri::HTML(
|
19
|
+
@document_html ||= Nokogiri::HTML(generate_html)
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_html
|
@@ -26,7 +26,7 @@ module FilmAffinity
|
|
26
26
|
def parse_movie
|
27
27
|
id = document_html.at('meta[property="og:url"]')['content'][/\d+/].to_i
|
28
28
|
title = document_html.at('meta[property="og:title"]')['content']
|
29
|
-
[FilmAffinity::Movie.new(id,title)]
|
29
|
+
[FilmAffinity::Movie.new(id, title)]
|
30
30
|
end
|
31
31
|
|
32
32
|
def parse_movies
|
@@ -43,6 +43,5 @@ module FilmAffinity
|
|
43
43
|
def to_json
|
44
44
|
@json_parser.to_json movies
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
end
|
data/lib/filmaffinity/top.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
require "pry"
|
3
1
|
module FilmAffinity
|
4
2
|
class Top
|
5
|
-
def initialize
|
3
|
+
def initialize(options: {}, limit: 30)
|
6
4
|
@options = options
|
7
5
|
@limit = limit
|
8
6
|
@json_parser = JsonMoviesParser.new
|
@@ -12,11 +10,11 @@ module FilmAffinity
|
|
12
10
|
@movies = movies_with_limit
|
13
11
|
end
|
14
12
|
|
15
|
-
def document_html
|
16
|
-
@document_html = Nokogiri::HTML(
|
13
|
+
def document_html(from)
|
14
|
+
@document_html = Nokogiri::HTML(generate_html(from))
|
17
15
|
end
|
18
16
|
|
19
|
-
def generate_html
|
17
|
+
def generate_html(from)
|
20
18
|
params = {'from' => from}
|
21
19
|
url = URI.parse(Constants.urls[:top] % query_options)
|
22
20
|
data = Net::HTTP.post_form(url, params)
|
@@ -24,12 +22,12 @@ module FilmAffinity
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def query_options
|
27
|
-
query_options =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
query_options.gsub(/\&$/,"")
|
25
|
+
query_options = ''
|
26
|
+
query_options += "?"
|
27
|
+
@options.each do |key, value|
|
28
|
+
query_options += Constants.query_params[key] % value
|
29
|
+
end
|
30
|
+
query_options.gsub(/\&$/, "")
|
33
31
|
end
|
34
32
|
|
35
33
|
def movies_with_limit
|
@@ -39,16 +37,16 @@ module FilmAffinity
|
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
def collect_from
|
40
|
+
def collect_from(collection = [], from = 0, &block)
|
43
41
|
response = yield(from)
|
44
42
|
collection += response
|
45
43
|
last_position = collection.size
|
46
|
-
response.empty? || last_position >= @limit ? collection.flatten[0..@limit-1] : collect_from(collection,last_position
|
44
|
+
response.empty? || last_position >= @limit ? collection.flatten[0..@limit - 1] : collect_from(collection, last_position, &block)
|
47
45
|
end
|
48
46
|
|
49
|
-
def parse_movies
|
47
|
+
def parse_movies(document_html)
|
50
48
|
movies = []
|
51
|
-
document_html.search(".movie-card.movie-card-1").each_with_index do |movie_card,
|
49
|
+
document_html.search(".movie-card.movie-card-1").each_with_index do |movie_card, _index|
|
52
50
|
id = movie_card["data-movie-id"].to_i
|
53
51
|
title = movie_card.search(".mc-title a").first.content.strip
|
54
52
|
movie = FilmAffinity::Movie.new id, title
|
@@ -60,6 +58,5 @@ module FilmAffinity
|
|
60
58
|
def to_json
|
61
59
|
@json_parser.to_json movies
|
62
60
|
end
|
63
|
-
|
64
61
|
end
|
65
62
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
require_relative "../spec_helper"
|
2
2
|
|
3
3
|
describe "JsonMovieParser" do
|
4
|
-
|
5
4
|
describe "#to_hash" do
|
6
5
|
subject { JsonMovieParser.new }
|
7
|
-
|
8
6
|
it "return the right director for the given movie" do
|
9
|
-
hash = subject.to_hash FilmAffinity::Movie.new(
|
7
|
+
hash = subject.to_hash FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)")
|
10
8
|
expect(hash["director"]).to eq("Peter Weir")
|
11
9
|
end
|
12
|
-
|
13
10
|
end
|
14
|
-
|
15
11
|
end
|
@@ -1,15 +1,11 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
describe "#to_hashes" do
|
3
|
+
describe 'JsonMoviesParser' do
|
4
|
+
describe '#to_hashes' do
|
6
5
|
subject { JsonMoviesParser.new }
|
7
|
-
|
8
|
-
|
9
|
-
hashes
|
10
|
-
expect(hashes.map {|hash| hash["id"]}).to include(193232, 504889)
|
6
|
+
it 'return some valid ids for a given search' do
|
7
|
+
hashes = subject.to_hashes FilmAffinity::Search.new('truman').movies
|
8
|
+
expect(hashes.map { |hash| hash['id'] }).to include(193_232, 504_889)
|
11
9
|
end
|
12
|
-
|
13
10
|
end
|
14
|
-
|
15
11
|
end
|
@@ -3,21 +3,21 @@ require_relative "../spec_helper"
|
|
3
3
|
describe "FilmAffinity::Movie" do
|
4
4
|
context "english version" do
|
5
5
|
describe "#title" do
|
6
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
6
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889) }
|
7
7
|
it "should return an valid title when initializes with no title" do
|
8
8
|
expect(movie.title).to eq("The Truman Show")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#rating" do
|
13
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
13
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
14
14
|
it "should return an Float" do
|
15
15
|
expect(movie.rating).to be_a(Float)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#year" do
|
20
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
20
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
21
21
|
it "should return an Fixnum" do
|
22
22
|
expect(movie.year).to be_an(Fixnum)
|
23
23
|
end
|
@@ -27,7 +27,7 @@ describe "FilmAffinity::Movie" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#duration" do
|
30
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
30
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
31
31
|
it "should return an Fixnum" do
|
32
32
|
expect(movie.duration).to be_a(Fixnum)
|
33
33
|
end
|
@@ -37,7 +37,7 @@ describe "FilmAffinity::Movie" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#country" do
|
40
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
40
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
41
41
|
it "should return a String" do
|
42
42
|
expect(movie.country).to be_a(String)
|
43
43
|
end
|
@@ -47,7 +47,7 @@ describe "FilmAffinity::Movie" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "#director" do
|
50
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
50
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
51
51
|
it "should return a String" do
|
52
52
|
expect(movie.director).to be_a(String)
|
53
53
|
end
|
@@ -57,7 +57,7 @@ describe "FilmAffinity::Movie" do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "#script" do
|
60
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
60
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
61
61
|
it "should return a String" do
|
62
62
|
expect(movie.script).to be_a(String)
|
63
63
|
end
|
@@ -67,7 +67,7 @@ describe "FilmAffinity::Movie" do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "#cast" do
|
70
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
70
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
71
71
|
it "should return an Array" do
|
72
72
|
expect(movie.cast).to be_an(Array)
|
73
73
|
end
|
@@ -83,7 +83,7 @@ describe "FilmAffinity::Movie" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
describe "#company" do
|
86
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
86
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
87
87
|
it "should return a String" do
|
88
88
|
expect(movie.company).to be_a(String)
|
89
89
|
end
|
@@ -93,7 +93,7 @@ describe "FilmAffinity::Movie" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
describe "#genres" do
|
96
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
96
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
97
97
|
it "should return an Array" do
|
98
98
|
expect(movie.genres).to be_an(Array)
|
99
99
|
end
|
@@ -108,7 +108,7 @@ describe "FilmAffinity::Movie" do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
describe "#poster" do
|
111
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
111
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
112
112
|
it "should return a String" do
|
113
113
|
expect(movie.poster).to be_a(String)
|
114
114
|
end
|
@@ -118,7 +118,7 @@ describe "FilmAffinity::Movie" do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
context "spanish version" do
|
121
|
+
context "spanish version" do
|
122
122
|
before :all do
|
123
123
|
FilmAffinity.configure do |config|
|
124
124
|
config.language = "ES"
|
@@ -126,21 +126,21 @@ context "spanish version" do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
describe "#title" do
|
129
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
129
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889) }
|
130
130
|
it "should return an valid title when initializes with no title" do
|
131
131
|
expect(movie.title).to eq("El show de Truman (Una vida en directo)")
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
describe "#rating" do
|
136
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
136
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
137
137
|
it "should return an Float" do
|
138
138
|
expect(movie.rating).to be_a(Float)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "#year" do
|
143
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
143
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
144
144
|
it "should return an Fixnum" do
|
145
145
|
expect(movie.year).to be_an(Fixnum)
|
146
146
|
end
|
@@ -150,7 +150,7 @@ context "spanish version" do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "#duration" do
|
153
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
153
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
154
154
|
it "should return an Fixnum" do
|
155
155
|
expect(movie.duration).to be_a(Fixnum)
|
156
156
|
end
|
@@ -160,7 +160,7 @@ context "spanish version" do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
describe "#country" do
|
163
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
163
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
164
164
|
it "should return a String" do
|
165
165
|
expect(movie.country).to be_a(String)
|
166
166
|
end
|
@@ -170,7 +170,7 @@ context "spanish version" do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
describe "#director" do
|
173
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
173
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
174
174
|
it "should return a String" do
|
175
175
|
expect(movie.director).to be_a(String)
|
176
176
|
end
|
@@ -180,7 +180,7 @@ context "spanish version" do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
describe "#script" do
|
183
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
183
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
184
184
|
it "should return a String" do
|
185
185
|
expect(movie.script).to be_a(String)
|
186
186
|
end
|
@@ -190,7 +190,7 @@ context "spanish version" do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
describe "#cast" do
|
193
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
193
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
194
194
|
it "should return an Array" do
|
195
195
|
expect(movie.cast).to be_an(Array)
|
196
196
|
end
|
@@ -206,7 +206,7 @@ context "spanish version" do
|
|
206
206
|
end
|
207
207
|
|
208
208
|
describe "#company" do
|
209
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
209
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
210
210
|
it "should return a String" do
|
211
211
|
expect(movie.company).to be_a(String)
|
212
212
|
end
|
@@ -216,7 +216,7 @@ context "spanish version" do
|
|
216
216
|
end
|
217
217
|
|
218
218
|
describe "#genres" do
|
219
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
219
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
220
220
|
it "should return an Array" do
|
221
221
|
expect(movie.genres).to be_an(Array)
|
222
222
|
end
|
@@ -231,7 +231,7 @@ context "spanish version" do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
describe "#poster" do
|
234
|
-
subject(:movie) { FilmAffinity::Movie.new(
|
234
|
+
subject(:movie) { FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)") }
|
235
235
|
it "should return a String" do
|
236
236
|
expect(movie.poster).to be_a(String)
|
237
237
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require_relative "../spec_helper"
|
2
2
|
require_relative "matchers/include-movie"
|
3
3
|
|
4
|
-
|
5
4
|
describe "FilmAffinity::Search" do
|
6
|
-
|
7
5
|
describe "#create_document_html" do
|
8
6
|
subject(:search) { FilmAffinity::Search.new("truman") }
|
9
7
|
|
@@ -11,7 +9,6 @@ describe "FilmAffinity::Search" do
|
|
11
9
|
document_html = search.document_html
|
12
10
|
expect(document_html).to be_an(Nokogiri::HTML::Document)
|
13
11
|
end
|
14
|
-
|
15
12
|
end
|
16
13
|
|
17
14
|
describe "#movies" do
|
@@ -27,17 +24,17 @@ describe "FilmAffinity::Search" do
|
|
27
24
|
end
|
28
25
|
it "should include 'Truman Show'" do
|
29
26
|
movies = search.movies
|
30
|
-
truman_movie = FilmAffinity::Movie.new
|
27
|
+
truman_movie = FilmAffinity::Movie.new(504_889, "El show de Truman (Una vida en directo)")
|
31
28
|
expect(movies).to include_movie(truman_movie)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
35
32
|
describe "#parse_movie" do
|
36
|
-
#Get a direct result from a specific searchs
|
33
|
+
# Get a direct result from a specific searchs
|
37
34
|
subject(:search) { FilmAffinity::Search.new("truman show") }
|
38
35
|
|
39
36
|
it "should parse id" do
|
40
|
-
id =
|
37
|
+
id = 504_889
|
41
38
|
expect(id).to eq(search.movies.first.id)
|
42
39
|
end
|
43
40
|
|
@@ -45,6 +42,5 @@ describe "FilmAffinity::Search" do
|
|
45
42
|
title = "El show de Truman (Una vida en directo) (1998)"
|
46
43
|
expect(title).to eq(search.movies.first.title)
|
47
44
|
end
|
48
|
-
|
49
45
|
end
|
50
46
|
end
|
@@ -2,7 +2,6 @@ require_relative "../spec_helper"
|
|
2
2
|
require "pry"
|
3
3
|
|
4
4
|
describe "FilmAffinity::Top" do
|
5
|
-
|
6
5
|
describe "#create_document_html" do
|
7
6
|
subject(:top) { FilmAffinity::Top.new }
|
8
7
|
|
@@ -10,85 +9,82 @@ describe "FilmAffinity::Top" do
|
|
10
9
|
document_html = top.document_html 0
|
11
10
|
expect(document_html).to respond_to(:search)
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
14
|
describe "#movies" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
it "should return just FilmAffinity::Movie objects only" do
|
24
|
-
movies = top.movies
|
25
|
-
movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
|
26
|
-
end
|
27
|
-
it "should include 'El Padrino'" do
|
28
|
-
movies = top.movies
|
29
|
-
el_padrino_movie = FilmAffinity::Movie.new 809297, "El padrino"
|
30
|
-
expect(movies).to include_movie(el_padrino_movie)
|
31
|
-
end
|
32
|
-
it "should return 30 movies" do
|
33
|
-
movies = top.movies
|
34
|
-
expect(movies.size).to eq(30)
|
35
|
-
end
|
15
|
+
context "no options" do
|
16
|
+
subject(:top) { FilmAffinity::Top.new }
|
17
|
+
it "should return an array" do
|
18
|
+
movies = top.movies
|
19
|
+
expect(movies).to be_an(Array)
|
36
20
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
expect(movies).to be_an(Array)
|
46
|
-
end
|
47
|
-
it "should return just FilmAffinity::Movie objects only" do
|
48
|
-
movies = top.movies
|
49
|
-
movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
|
50
|
-
end
|
51
|
-
it "should include 'Hijos del Tercer Reich (TV)'" do
|
52
|
-
movies = top.movies
|
53
|
-
hijos_del_tercer_reich_movie = FilmAffinity::Movie.new 831118, "Hijos del Tercer Reich (TV)"
|
54
|
-
expect(movies).to include_movie(hijos_del_tercer_reich_movie)
|
55
|
-
end
|
56
|
-
|
21
|
+
it "should return just FilmAffinity::Movie objects only" do
|
22
|
+
movies = top.movies
|
23
|
+
movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
|
24
|
+
end
|
25
|
+
it "should include 'El Padrino'" do
|
26
|
+
movies = top.movies
|
27
|
+
el_padrino_movie = FilmAffinity::Movie.new(809_297, "El padrino")
|
28
|
+
expect(movies).to include_movie(el_padrino_movie)
|
57
29
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
it "should include 'American History X'" do
|
62
|
-
movies = top.movies
|
63
|
-
american_history_x = FilmAffinity::Movie.new 261972, "American History X"
|
64
|
-
expect(movies).to include_movie(american_history_x)
|
65
|
-
end
|
66
|
-
it "should NOT include 'Con la muerte en los talones'" do
|
67
|
-
movies = top.movies
|
68
|
-
con_la_muerte_en_los_talones = FilmAffinity::Movie.new 351704, "Con la muerte en los talones"
|
69
|
-
expect(movies).not_to include_movie(con_la_muerte_en_los_talones)
|
70
|
-
end
|
71
|
-
it "should return 60 movies" do
|
72
|
-
movies = top.movies
|
73
|
-
expect(movies.size).to eq(60)
|
74
|
-
end
|
30
|
+
it "should return 30 movies" do
|
31
|
+
movies = top.movies
|
32
|
+
expect(movies.size).to eq(30)
|
75
33
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
34
|
+
end
|
35
|
+
context "with options" do
|
36
|
+
options = {
|
37
|
+
genre: "BE",
|
38
|
+
country: "DE"
|
39
|
+
}
|
40
|
+
subject(:top) { FilmAffinity::Top.new options: options }
|
41
|
+
it "should return an array" do
|
42
|
+
movies = top.movies
|
43
|
+
expect(movies).to be_an(Array)
|
44
|
+
end
|
45
|
+
it "should return just FilmAffinity::Movie objects only" do
|
46
|
+
movies = top.movies
|
47
|
+
movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
|
83
48
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
movies = top.movies
|
89
|
-
expect(movies.size).to eq(10)
|
90
|
-
end
|
49
|
+
it "should include 'Hijos del Tercer Reich (TV)'" do
|
50
|
+
movies = top.movies
|
51
|
+
hijos_del_tercer_reich_movie = FilmAffinity::Movie.new(831_118, "Hijos del Tercer Reich (TV)")
|
52
|
+
expect(movies).to include_movie(hijos_del_tercer_reich_movie)
|
91
53
|
end
|
92
54
|
end
|
93
|
-
|
55
|
+
context "with limit 60" do
|
56
|
+
limit = 60
|
57
|
+
subject(:top) { FilmAffinity::Top.new limit: limit }
|
58
|
+
it "should include 'American History X'" do
|
59
|
+
movies = top.movies
|
60
|
+
american_history_x = FilmAffinity::Movie.new(261_972, "American History X")
|
61
|
+
expect(movies).to include_movie(american_history_x)
|
62
|
+
end
|
63
|
+
it "should NOT include 'Con la muerte en los talones'" do
|
64
|
+
movies = top.movies
|
65
|
+
con_la_muerte_en_los_talones = FilmAffinity::Movie.new(351_704, "Con la muerte en los talones")
|
66
|
+
expect(movies).not_to include_movie(con_la_muerte_en_los_talones)
|
67
|
+
end
|
68
|
+
it "should return 60 movies" do
|
69
|
+
movies = top.movies
|
70
|
+
expect(movies.size).to eq(60)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "with limit 132" do
|
74
|
+
limit = 132
|
75
|
+
subject(:top) { FilmAffinity::Top.new limit: limit }
|
76
|
+
it "should return 132 movies" do
|
77
|
+
movies = top.movies
|
78
|
+
expect(movies.size).to eq(132)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context "with limit 10" do
|
82
|
+
limit = 10
|
83
|
+
subject(:top) { FilmAffinity::Top.new limit: limit }
|
84
|
+
it "should return 10 movies" do
|
85
|
+
movies = top.movies
|
86
|
+
expect(movies.size).to eq(10)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
94
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filmaffinity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santos
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -88,6 +88,8 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".rubocop_todo.yml"
|
91
93
|
- Gemfile
|
92
94
|
- Gemfile.lock
|
93
95
|
- README.md
|