picturehouse_uk 1.0.0

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.
Files changed (35) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +4 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +64 -0
  6. data/Rakefile +20 -0
  7. data/lib/picturehouse_uk.rb +16 -0
  8. data/lib/picturehouse_uk/cinema.rb +129 -0
  9. data/lib/picturehouse_uk/film.rb +52 -0
  10. data/lib/picturehouse_uk/internal/film_with_screenings_parser.rb +48 -0
  11. data/lib/picturehouse_uk/screening.rb +33 -0
  12. data/lib/picturehouse_uk/version.rb +3 -0
  13. data/picturehouse_uk.gemspec +29 -0
  14. data/test/fixtures/dukes-at-komedia-cinema.html +7148 -0
  15. data/test/fixtures/film_node/blue-jasmine-done.html +53 -0
  16. data/test/fixtures/film_node/blue-jasmine-future.html +55 -0
  17. data/test/fixtures/film_node/bolshoi-spartacus.html +26 -0
  18. data/test/fixtures/film_node/captain-phillips-with-silver-screen-and-subtitles.html +103 -0
  19. data/test/fixtures/film_node/fifth-estate-with-big-scream.html +73 -0
  20. data/test/fixtures/film_node/london-film-festival-with-toddler-time.html +46 -0
  21. data/test/fixtures/film_node/met-encore-rusalka-as-live.html +26 -0
  22. data/test/fixtures/film_node/nt-encore-hamlet.html +26 -0
  23. data/test/fixtures/film_node/planes-with-kids-club.html +77 -0
  24. data/test/fixtures/film_node/royal-opera-house-don-quixote.html +26 -0
  25. data/test/fixtures/film_node/rsc-encore-richard-ii.html +28 -0
  26. data/test/fixtures/film_node/rsc-live-richard-ii.html +41 -0
  27. data/test/fixtures/film_node/rsc-live-the-two-gentlemen-of-verona-zero-cert.html +19 -0
  28. data/test/fixtures/picturehouses-homepage.html +1454 -0
  29. data/test/lib/picturehouse_uk/cinema_test.rb +129 -0
  30. data/test/lib/picturehouse_uk/film_test.rb +92 -0
  31. data/test/lib/picturehouse_uk/internal/film_with_screenings_parser_test.rb +185 -0
  32. data/test/lib/picturehouse_uk/screening_test.rb +32 -0
  33. data/test/lib/picturehouse_uk/version_test.rb +7 -0
  34. data/test/test_helper.rb +6 -0
  35. metadata +213 -0
@@ -0,0 +1,129 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe PicturehouseUk::Cinema do
4
+
5
+ before { WebMock.disable_net_connect! }
6
+
7
+ describe '.all' do
8
+ subject { PicturehouseUk::Cinema.all }
9
+
10
+ before do
11
+ homepage_body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'picturehouses-homepage.html') )
12
+ stub_request(:get, 'http://www.picturehouses.co.uk/').to_return( status: 200, body: homepage_body, headers: {} )
13
+ end
14
+
15
+ it 'returns an Array of PicturehouseUk::Cinemas' do
16
+ subject.must_be_instance_of(Array)
17
+ subject.each do |value|
18
+ value.must_be_instance_of(PicturehouseUk::Cinema)
19
+ end
20
+ end
21
+
22
+ it 'returns the correctly sized array' do
23
+ subject.size.must_equal 21
24
+ end
25
+
26
+ it 'returns the right cinemas' do
27
+ subject.first.name.must_equal 'Clapham Picturehouse'
28
+ subject.last.name.must_equal 'City Screen Picturehouse'
29
+ end
30
+ end
31
+
32
+ describe '.find(id)' do
33
+ let(:id) { 'Dukes_At_Komedia' }
34
+
35
+ subject { PicturehouseUk::Cinema.find(id) }
36
+
37
+ before do
38
+ homepage_body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'picturehouses-homepage.html') )
39
+ stub_request(:get, 'http://www.picturehouses.co.uk/').to_return( status: 200, body: homepage_body, headers: {} )
40
+ end
41
+
42
+ it 'returns a cinema' do
43
+ subject.must_be_instance_of(PicturehouseUk::Cinema)
44
+
45
+ subject.id.must_equal 'Dukes_At_Komedia'
46
+ subject.brand.must_equal 'Picturehouse'
47
+ subject.name.must_equal "Duke's At Komedia"
48
+ subject.slug.must_equal 'dukes-at-komedia'
49
+ subject.url.must_equal 'http://www.picturehouses.co.uk/cinema/Dukes_At_Komedia/'
50
+ end
51
+ end
52
+
53
+ describe '.new id, name, url' do
54
+ it 'stores id, name, slug and url' do
55
+ cinema = PicturehouseUk::Cinema.new 'Dukes_At_Komedia', "Duke's At Komedia", '/cinema/Dukes_At_Komedia/'
56
+ cinema.id.must_equal 'Dukes_At_Komedia'
57
+ cinema.brand.must_equal 'Picturehouse'
58
+ cinema.name.must_equal "Duke's At Komedia"
59
+ cinema.slug.must_equal 'dukes-at-komedia'
60
+ cinema.url.must_equal 'http://www.picturehouses.co.uk/cinema/Dukes_At_Komedia/'
61
+ end
62
+ end
63
+
64
+ describe '#films' do
65
+ let(:cinema) { PicturehouseUk::Cinema.new 'Dukes_At_Komedia', "Duke's At Komedia", '/cinema/Dukes_At_Komedia/' }
66
+ subject { cinema.films }
67
+
68
+ before do
69
+ dukes_cinema_body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'dukes-at-komedia-cinema.html') )
70
+ stub_request(:get, 'http://www.picturehouses.co.uk/cinema/Dukes_At_Komedia/').to_return( status: 200, body: dukes_cinema_body, headers: {} )
71
+ end
72
+
73
+ it 'returns an array of films' do
74
+ subject.must_be_instance_of(Array)
75
+ subject.each do |item|
76
+ item.must_be_instance_of(PicturehouseUk::Film)
77
+ end
78
+ end
79
+
80
+ it 'returns correct number of films' do
81
+ subject.count.must_equal 37
82
+ end
83
+
84
+ it 'returns uniquely named films' do
85
+ first_name = subject.first.name
86
+ first = subject.first
87
+
88
+ subject[1..-1].each { |item| item.name.wont_equal first_name }
89
+ subject[1..-1].each { |item| item.wont_equal first }
90
+ end
91
+
92
+ it 'returns film objects with correct names' do
93
+ subject.first.name.must_equal 'Blue Jasmine'
94
+ subject.last.name.must_equal 'Royal Opera House: Manon Lescaut'
95
+ end
96
+ end
97
+
98
+ describe '#screenings' do
99
+ let(:cinema) { PicturehouseUk::Cinema.new('Dukes_At_Komedia', "Duke's At Komedia", '/cinema/Dukes_At_Komedia/') }
100
+ subject { cinema.screenings }
101
+
102
+ before do
103
+ dukes_cinema_body = File.read( File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'dukes-at-komedia-cinema.html') )
104
+ stub_request(:get, 'http://www.picturehouses.co.uk/cinema/Dukes_At_Komedia/').to_return( status: 200, body: dukes_cinema_body, headers: {} )
105
+ end
106
+
107
+ it 'returns an array of screenings' do
108
+ subject.must_be_instance_of(Array)
109
+ subject.each do |item|
110
+ item.must_be_instance_of(PicturehouseUk::Screening)
111
+ end
112
+ end
113
+
114
+ it 'returns screening objects with correct film names' do
115
+ subject.first.film_name.must_equal 'Blue Jasmine'
116
+ subject.last.film_name.must_equal 'Royal Opera House: Manon Lescaut'
117
+ end
118
+
119
+ it 'returns screening objects with correct cinema name' do
120
+ subject.each { |s| s.cinema_name.must_equal "Duke's At Komedia" }
121
+ end
122
+
123
+ it 'returns screening objects with correct UTC times' do
124
+ subject.first.when.must_equal Time.utc(2013, 10, 14, 20, 0, 0)
125
+ subject.last.when.must_equal Time.utc(2014, 6, 24, 17, 45, 0)
126
+ end
127
+ end
128
+
129
+ end
@@ -0,0 +1,92 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe PicturehouseUk::Film do
4
+ describe '.new(name)' do
5
+ it 'stores name' do
6
+ film = PicturehouseUk::Film.new 'Iron Man 3'
7
+ film.name.must_equal 'Iron Man 3'
8
+ end
9
+ end
10
+
11
+ describe 'Comparable' do
12
+ it 'includes comparable methods' do
13
+ film = PicturehouseUk::Film.new 'AAAA'
14
+ film.methods.must_include :<
15
+ film.methods.must_include :>
16
+ film.methods.must_include :==
17
+ film.methods.must_include :<=>
18
+ film.methods.must_include :<=
19
+ film.methods.must_include :>=
20
+ end
21
+
22
+ describe 'uniqueness' do
23
+ it 'defines #hash' do
24
+ film = PicturehouseUk::Film.new 'AAAA'
25
+ film.methods.must_include :hash
26
+ end
27
+
28
+ describe '#hash' do
29
+ it 'returns a hash of the slug' do
30
+ film = PicturehouseUk::Film.new 'AAAA'
31
+ film.hash == film.slug.hash
32
+ end
33
+ end
34
+
35
+ it 'defines #eql?(other)' do
36
+ film = PicturehouseUk::Film.new 'AAAA'
37
+ film.methods.must_include :eql?
38
+ end
39
+
40
+ describe 'two identically named films' do
41
+ let(:film) { PicturehouseUk::Film.new 'AAAA' }
42
+ let(:otherfilm) { PicturehouseUk::Film.new 'AAAA' }
43
+
44
+ it 'retuns only one' do
45
+ result = [film, otherfilm].uniq
46
+ result.count.must_equal 1
47
+ result.must_equal [ PicturehouseUk::Film.new('AAAA') ]
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '<=> (other)' do
53
+ subject { film <=> otherfilm }
54
+
55
+ describe 'film less than other' do
56
+ let(:film) { PicturehouseUk::Film.new 'AAAA' }
57
+ let(:otherfilm) { PicturehouseUk::Film.new 'BBBB' }
58
+
59
+ it 'retuns -1' do
60
+ subject.must_equal -1
61
+ end
62
+ end
63
+
64
+ describe 'film greater than other' do
65
+ let(:film) { PicturehouseUk::Film.new 'CCCC' }
66
+ let(:otherfilm) { PicturehouseUk::Film.new 'BBBB' }
67
+
68
+ it 'retuns 1' do
69
+ subject.must_equal 1
70
+ end
71
+ end
72
+
73
+ describe 'film same as other (exact name)' do
74
+ let(:film) { PicturehouseUk::Film.new 'AAAA' }
75
+ let(:otherfilm) { PicturehouseUk::Film.new 'AAAA' }
76
+
77
+ it 'retuns 0' do
78
+ subject.must_equal 0
79
+ end
80
+ end
81
+
82
+ describe 'film same as other (inexact name)' do
83
+ let(:film) { PicturehouseUk::Film.new 'blue jasmine' }
84
+ let(:otherfilm) { PicturehouseUk::Film.new 'Blue Jasmine' }
85
+
86
+ it 'retuns 0' do
87
+ subject.must_equal 0
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,185 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe PicturehouseUk::Internal::FilmWithScreeningsParser do
4
+
5
+ describe '#film_name' do
6
+ subject { PicturehouseUk::Internal::FilmWithScreeningsParser.new(film_html).film_name }
7
+
8
+ describe 'simple name' do
9
+ let(:film_html) { read_film_html 'blue-jasmine-future'}
10
+
11
+ it 'removes certificate' do
12
+ subject.must_be_instance_of String
13
+ subject.must_equal 'Blue Jasmine'
14
+ end
15
+ end
16
+
17
+ describe 'simple name with dimensionality' do
18
+ let(:film_html) { read_film_html 'planes-with-kids-club'}
19
+
20
+ it 'removes version designation' do
21
+ subject.must_be_instance_of String
22
+ subject.must_equal 'Planes'
23
+ end
24
+ end
25
+
26
+ describe 'royal opera house with no cert' do
27
+ let(:film_html) { read_film_html 'royal-opera-house-don-quixote'}
28
+
29
+ it 'removes live designation, certificate and spells out Royal Opera House' do
30
+ subject.must_be_instance_of String
31
+ subject.must_equal 'Royal Opera House: Don Quixote'
32
+ end
33
+ end
34
+
35
+ describe 'bolshoi with no cert' do
36
+ let(:film_html) { read_film_html 'bolshoi-spartacus'}
37
+
38
+ it 'removes certificate' do
39
+ subject.must_be_instance_of String
40
+ subject.must_equal 'Bolshoi: Spartacus'
41
+ end
42
+ end
43
+
44
+ describe 'nt encore with no cert' do
45
+ let(:film_html) { read_film_html 'nt-encore-hamlet'}
46
+
47
+ it 'removes certificate' do
48
+ subject.must_be_instance_of String
49
+ subject.must_equal 'National Theatre: Hamlet'
50
+ end
51
+ end
52
+
53
+ describe 'rsc live with no cert' do
54
+ let(:film_html) { read_film_html 'rsc-live-richard-ii'}
55
+
56
+ it 'removes certificate' do
57
+ subject.must_be_instance_of String
58
+ subject.must_equal 'Royal Shakespeare Company: Richard II'
59
+ end
60
+ end
61
+
62
+ describe 'rsc encore with no cert' do
63
+ let(:film_html) { read_film_html 'rsc-encore-richard-ii'}
64
+
65
+ it 'removes certificate' do
66
+ subject.must_be_instance_of String
67
+ subject.must_equal 'Royal Shakespeare Company: Richard II'
68
+ end
69
+ end
70
+
71
+ describe 'met encore as live with no cert' do
72
+ let(:film_html) { read_film_html 'met-encore-rusalka-as-live'}
73
+
74
+ it 'removes certificate' do
75
+ subject.must_be_instance_of String
76
+ subject.must_equal 'Met Opera: Rusalka'
77
+ end
78
+ end
79
+
80
+ describe 'rsc live with zeroed cert' do
81
+ let(:film_html) { read_film_html 'rsc-live-the-two-gentlemen-of-verona-zero-cert' }
82
+
83
+ it 'removes certificate' do
84
+ subject.must_be_instance_of String
85
+ subject.must_equal 'Royal Shakespeare Company: The Two Gentlemen of Verona'
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#showings' do
91
+ subject { PicturehouseUk::Internal::FilmWithScreeningsParser.new(film_html).showings }
92
+
93
+ describe 'multiple screenings' do
94
+ let(:film_html) { read_film_html 'blue-jasmine-future'}
95
+
96
+ it 'returns a hash keyed by type of performance' do
97
+ subject.must_be_instance_of Hash
98
+ subject.keys.each { |key| key.must_be_instance_of String }
99
+ end
100
+
101
+ it 'returns an array of Times for each type of performance' do
102
+ subject.each do |key, value|
103
+ value.must_be_instance_of Array
104
+ value.each do |item|
105
+ item.must_be_instance_of Time
106
+ end
107
+ end
108
+ end
109
+
110
+ it 'returns the correct number of Times' do
111
+ subject.keys.must_equal ['2d']
112
+ subject['2d'].count.must_equal 2
113
+ end
114
+
115
+ it 'returns Times in UTC' do
116
+ subject['2d'].first.must_equal Time.utc(2013, 10, 15, 9, 30, 0)
117
+ subject['2d'].last.must_equal Time.utc(2013, 10, 15, 20, 15, 0)
118
+ end
119
+ end
120
+
121
+ describe 'screenings including OAP & subtitled' do
122
+ let(:film_html) { read_film_html 'captain-phillips-with-silver-screen-and-subtitles'}
123
+
124
+ it 'returns an array of Times for each type of performance' do
125
+ subject.each do |key, value|
126
+ value.must_be_instance_of Array
127
+ value.each do |item|
128
+ item.must_be_instance_of Time
129
+ end
130
+ end
131
+ end
132
+
133
+ it 'returns the correct number of Times' do
134
+ subject.keys.sort.must_equal ['2d', 'silver', 'subtitled']
135
+
136
+ subject['2d'].count.must_equal 1
137
+ subject['silver'].count.must_equal 2
138
+ subject['subtitled'].count.must_equal 1
139
+ end
140
+ end
141
+
142
+ describe 'screenings including toddler time' do
143
+ let(:film_html) { read_film_html 'london-film-festival-with-toddler-time'}
144
+
145
+ it 'returns the correct number of Times' do
146
+ subject.keys.must_equal ['kids']
147
+ subject['kids'].count.must_equal 1
148
+ end
149
+ end
150
+
151
+ describe 'screenings including baby' do
152
+ let(:film_html) { read_film_html 'fifth-estate-with-big-scream'}
153
+
154
+ it 'returns the correct number of Times' do
155
+ subject.keys.sort.must_equal ['2d', 'baby']
156
+
157
+ subject['2d'].count.must_equal 4
158
+ subject['baby'].count.must_equal 1
159
+ end
160
+ end
161
+
162
+ describe 'screenings including kids' do
163
+ let(:film_html) { read_film_html 'planes-with-kids-club'}
164
+
165
+ it 'returns the correct number of Times' do
166
+ subject.keys.must_equal ['kids']
167
+ subject['kids'].count.must_equal 1
168
+ end
169
+ end
170
+
171
+ describe 'expired screenings' do
172
+ let(:film_html) { read_film_html 'blue-jasmine-done'}
173
+
174
+ it 'returns an empty hash' do
175
+ subject.must_be_instance_of Hash
176
+ subject.must_be_empty
177
+ end
178
+ end
179
+ end
180
+
181
+ def read_film_html(filename)
182
+ path = "../../../../fixtures/film_node"
183
+ File.read(File.expand_path("#{path}/#{filename}.html", __FILE__))
184
+ end
185
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe PicturehouseUk::Screening do
4
+
5
+ before { WebMock.disable_net_connect! }
6
+
7
+ describe '#new film_name, cinema_name, date, time, varient' do
8
+ it 'stores film_name, cinema_name & when (in UTC)' do
9
+ screening = PicturehouseUk::Screening.new 'Iron Man 3', "Duke's At Komedia", Time.parse('2013-09-12 11:00')
10
+ screening.film_name.must_equal 'Iron Man 3'
11
+ screening.cinema_name.must_equal "Duke's At Komedia"
12
+ screening.when.must_equal Time.utc(2013, 9, 12, 10, 0)
13
+ screening.varient.must_equal nil
14
+ end
15
+
16
+ it 'stores varient if passed' do
17
+ screening = PicturehouseUk::Screening.new 'Iron Man 3', "Duke's At Komedia", Time.utc(2013, 9, 12, 11, 0), 'baby'
18
+ screening.film_name.must_equal 'Iron Man 3'
19
+ screening.cinema_name.must_equal "Duke's At Komedia"
20
+ screening.when.must_equal Time.utc(2013, 9, 12, 11, 0)
21
+ screening.varient.must_equal 'baby'
22
+ end
23
+ end
24
+
25
+ describe '#date' do
26
+ subject { PicturehouseUk::Screening.new('Iron Man 3', "Duke's At Komedia", Time.utc(2013, 9, 12, 11, 0), '3d').date }
27
+ it 'should return date of showing' do
28
+ subject.must_be_instance_of(Date)
29
+ subject.must_equal Date.new(2013, 9, 12)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe PicturehouseUk do
4
+ it 'must be defined' do
5
+ PicturehouseUk::VERSION.wont_be_nil
6
+ end
7
+ end