picturehouse_uk 2.0.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -6
  3. data/README.md +9 -1
  4. data/lib/picturehouse_uk.rb +2 -3
  5. data/lib/picturehouse_uk/cinema.rb +24 -12
  6. data/lib/picturehouse_uk/film.rb +3 -5
  7. data/lib/picturehouse_uk/internal/parser/address.rb +37 -0
  8. data/lib/picturehouse_uk/internal/parser/screenings.rb +117 -0
  9. data/lib/picturehouse_uk/internal/title_sanitizer.rb +2 -0
  10. data/lib/picturehouse_uk/internal/website.rb +4 -10
  11. data/lib/picturehouse_uk/screening.rb +5 -15
  12. data/lib/picturehouse_uk/version.rb +2 -2
  13. data/test/fixture_updater.rb +16 -13
  14. data/test/fixtures/cinema/Duke_Of_Yorks.html +2048 -4341
  15. data/test/fixtures/cinema/Dukes_At_Komedia.html +3780 -0
  16. data/test/fixtures/cinema/Phoenix_Picturehouse.html +3465 -0
  17. data/test/fixtures/home.html +487 -1932
  18. data/test/fixtures/info/Duke_Of_Yorks.html +450 -0
  19. data/test/fixtures/info/Dukes_At_Komedia.html +439 -0
  20. data/test/fixtures/info/Phoenix_Picturehouse.html +458 -0
  21. data/test/lib/picturehouse_uk/cinema_test.rb +53 -16
  22. data/test/lib/picturehouse_uk/internal/parser/screenings_test.rb +45 -0
  23. data/test/lib/picturehouse_uk/internal/title_sanitizer_test.rb +16 -0
  24. data/test/lib/picturehouse_uk/internal/website_test.rb +6 -6
  25. data/test/lib/picturehouse_uk/screening_test.rb +9 -1
  26. metadata +16 -25
  27. data/lib/picturehouse_uk/internal/address_parser.rb +0 -72
  28. data/lib/picturehouse_uk/internal/cinema_page.rb +0 -35
  29. data/lib/picturehouse_uk/internal/film_with_screenings_parser.rb +0 -116
  30. data/test/fixtures/address-fragments/duke-of-yorks.html +0 -39
  31. data/test/fixtures/address-fragments/hackney-picturehouse.html +0 -12
  32. data/test/fixtures/cinema/Duke_Of_Yorks/film_last.html +0 -45
  33. data/test/fixtures/cinema/Duke_Of_Yorks/film_second.html +0 -37
  34. data/test/fixtures/cinema/York_Picturehouse/basement.html +0 -19
  35. data/test/fixtures/contact_us/Duke_Of_Yorks.html +0 -1505
  36. data/test/fixtures/contact_us/Dukes_At_Komedia.html +0 -1503
  37. data/test/lib/picturehouse_uk/internal/address_parser_test.rb +0 -55
  38. data/test/lib/picturehouse_uk/internal/cinema_page_test.rb +0 -51
  39. data/test/lib/picturehouse_uk/internal/film_with_screenings_parser_test.rb +0 -95
@@ -22,13 +22,13 @@ describe PicturehouseUk::Cinema do
22
22
 
23
23
  it 'returns the correctly sized array' do
24
24
  PicturehouseUk::Internal::Website.stub :new, website do
25
- subject.size.must_equal 22
25
+ subject.size.must_equal 12
26
26
  end
27
27
  end
28
28
 
29
29
  it 'returns the right cinemas' do
30
30
  PicturehouseUk::Internal::Website.stub :new, website do
31
- subject.first.name.must_equal 'Clapham Picturehouse'
31
+ subject.first.name.must_equal "Duke of York's Picturehouse"
32
32
  subject.last.name.must_equal 'City Screen Picturehouse'
33
33
  end
34
34
  end
@@ -47,7 +47,7 @@ describe PicturehouseUk::Cinema do
47
47
  subject.brand.must_equal 'Picturehouse'
48
48
  subject.name.must_equal "Duke of York's Picturehouse"
49
49
  subject.slug.must_equal 'duke-of-yorks-picturehouse'
50
- subject.url.must_equal "http://www.picturehouses.co.uk/cinema/#{id}/"
50
+ subject.url.must_equal "http://www.picturehouses.com/cinema/#{id}"
51
51
  end
52
52
  end
53
53
  end
@@ -57,7 +57,7 @@ describe PicturehouseUk::Cinema do
57
57
  {
58
58
  id: 'Dukes_At_Komedia',
59
59
  name: "Duke's At Komedia",
60
- url: '/cinema/Dukes_At_Komedia/'
60
+ url: '/cinema/Dukes_At_Komedia'
61
61
  }
62
62
  end
63
63
 
@@ -68,7 +68,34 @@ describe PicturehouseUk::Cinema do
68
68
  subject.brand.must_equal 'Picturehouse'
69
69
  subject.name.must_equal "Duke's At Komedia"
70
70
  subject.slug.must_equal 'dukes-at-komedia'
71
- subject.url.must_equal 'http://www.picturehouses.co.uk/cinema/Dukes_At_Komedia/'
71
+ subject.url.must_equal 'http://www.picturehouses.com/cinema/Dukes_At_Komedia'
72
+ end
73
+ end
74
+
75
+ describe '#adr' do
76
+ let(:options) do
77
+ {
78
+ id: 'Phoenix_Picturehouse',
79
+ name: "Pheonix Picturehouse",
80
+ url: '/cinema/Phoenix_Picturehouse'
81
+ }
82
+ end
83
+
84
+ describe '#adr' do
85
+ subject { described_class.new(options).adr }
86
+
87
+ it 'returns address hash' do
88
+ PicturehouseUk::Internal::Website.stub :new, website do
89
+ subject.must_equal(
90
+ street_address: '57 Walton Street',
91
+ extended_address: nil,
92
+ locality: 'Oxford',
93
+ region: nil,
94
+ postal_code: 'OX2 6AE',
95
+ country: 'United Kingdom'
96
+ )
97
+ end
98
+ end
72
99
  end
73
100
  end
74
101
 
@@ -77,7 +104,7 @@ describe PicturehouseUk::Cinema do
77
104
  {
78
105
  id: 'Dukes_At_Komedia',
79
106
  name: "Duke's At Komedia",
80
- url: '/cinema/Dukes_At_Komedia/'
107
+ url: '/cinema/Dukes_At_Komedia'
81
108
  }
82
109
  end
83
110
 
@@ -87,9 +114,10 @@ describe PicturehouseUk::Cinema do
87
114
  it 'returns address hash' do
88
115
  PicturehouseUk::Internal::Website.stub :new, website do
89
116
  subject.must_equal(
90
- street_address: '44-47 Gardner Street',
91
- extended_address: 'North Laine',
117
+ street_address: '4447 Gardner Street',
118
+ extended_address: nil,
92
119
  locality: 'Brighton',
120
+ region: 'East Sussex',
93
121
  postal_code: 'BN1 1UN',
94
122
  country: 'United Kingdom'
95
123
  )
@@ -102,7 +130,7 @@ describe PicturehouseUk::Cinema do
102
130
 
103
131
  it 'returns first line of address' do
104
132
  PicturehouseUk::Internal::Website.stub :new, website do
105
- subject.must_equal('44-47 Gardner Street')
133
+ subject.must_equal('4447 Gardner Street')
106
134
  end
107
135
  end
108
136
  end
@@ -112,7 +140,7 @@ describe PicturehouseUk::Cinema do
112
140
 
113
141
  it 'returns second line of address' do
114
142
  PicturehouseUk::Internal::Website.stub :new, website do
115
- subject.must_equal('North Laine')
143
+ subject.must_equal(nil)
116
144
  end
117
145
  end
118
146
  end
@@ -127,6 +155,16 @@ describe PicturehouseUk::Cinema do
127
155
  end
128
156
  end
129
157
 
158
+ describe '#region' do
159
+ subject { described_class.new(options).region }
160
+
161
+ it 'returns second line of address' do
162
+ PicturehouseUk::Internal::Website.stub :new, website do
163
+ subject.must_equal('East Sussex')
164
+ end
165
+ end
166
+ end
167
+
130
168
  describe '#postal_code' do
131
169
  subject { described_class.new(options).postal_code }
132
170
 
@@ -136,7 +174,6 @@ describe PicturehouseUk::Cinema do
136
174
  end
137
175
  end
138
176
  end
139
-
140
177
  end
141
178
 
142
179
  describe '#films' do
@@ -144,7 +181,7 @@ describe PicturehouseUk::Cinema do
144
181
  {
145
182
  id: 'Dukes_At_Komedia',
146
183
  name: "Duke's At Komedia",
147
- url: '/cinema/Dukes_At_Komedia/'
184
+ url: '/cinema/Dukes_At_Komedia'
148
185
  }
149
186
  end
150
187
 
@@ -162,7 +199,7 @@ describe PicturehouseUk::Cinema do
162
199
  {
163
200
  id: 'Dukes_At_Komedia',
164
201
  name: "Duke's At Komedia",
165
- url: '/cinema/Dukes_At_Komedia/'
202
+ url: '/cinema/Dukes_At_Komedia'
166
203
  }
167
204
  end
168
205
 
@@ -178,7 +215,7 @@ describe PicturehouseUk::Cinema do
178
215
  {
179
216
  id: 'Dukes_At_Komedia',
180
217
  name: "Duke's At Komedia",
181
- url: '/cinema/Dukes_At_Komedia/'
218
+ url: '/cinema/Dukes_At_Komedia'
182
219
  }
183
220
  end
184
221
 
@@ -202,8 +239,8 @@ describe PicturehouseUk::Cinema do
202
239
  read_file("../../../fixtures/cinema/#{filename}.html")
203
240
  end
204
241
 
205
- def contact_us(filename)
206
- read_file("../../../fixtures/contact_us/#{filename}.html")
242
+ def info(filename)
243
+ read_file("../../../fixtures/info/#{filename}.html")
207
244
  end
208
245
 
209
246
  private
@@ -0,0 +1,45 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ describe PicturehouseUk::Internal::Parser::Screenings do
4
+ let(:described_class) { PicturehouseUk::Internal::Parser::Screenings }
5
+
6
+ let(:website) { Minitest::Mock.new }
7
+
8
+ before do
9
+ WebMock.disable_net_connect!
10
+ end
11
+
12
+ %w(Duke_Of_Yorks Dukes_At_Komedia Pheonix_Oxford) do |cinema|
13
+ describe '#to_a' do
14
+ subject { described_class.new(cinema).to_a }
15
+
16
+ before { website.expect(:cinema, html(cinema), [cinema]) }
17
+
18
+ it 'returns an non-zero array of hashes' do
19
+ PicturehouseUk::Internal::Website.stub :new, website do
20
+ subject.must_be_instance_of(Array)
21
+ subject.size.must_be :>, 0
22
+
23
+ subject.each do |element|
24
+ element.must_be_instance_of(Hash)
25
+ element.keys.must_equal([:film_name, :dimension, :variant, :booking_url, :time])
26
+ element[:film_name].must_be_kind_of(String)
27
+ element[:dimension].must_match(/\A[23]d\z/)
28
+ element[:booking_url].must_match(/\Ahttps?\:\/\//)
29
+ element[:time].must_be_kind_of(Time)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def read_file(filepath)
39
+ File.read(File.expand_path(filepath, __FILE__))
40
+ end
41
+
42
+ def html(cinema)
43
+ read_file("../../../../../fixtures/cinema/#{cinema}.html")
44
+ end
45
+ end
@@ -343,5 +343,21 @@ describe PicturehouseUk::Internal::TitleSanitizer do
343
343
  subject.must_equal('The Hobbit: The Battle of the Five Armies')
344
344
  end
345
345
  end
346
+
347
+ describe 'live' do
348
+ let(:title) { 'English National Opera: Carmen (Live)' }
349
+
350
+ it 'removes live suffix' do
351
+ subject.must_equal('English National Opera: Carmen')
352
+ end
353
+ end
354
+
355
+ describe 'remove [TBC] certificate' do
356
+ let(:title) { 'The Living Room with Gavin Clark [TBC]' }
357
+
358
+ it 'removes tbc cert' do
359
+ subject.must_equal('The Living Room with Gavin Clark')
360
+ end
361
+ end
346
362
  end
347
363
  end
@@ -6,19 +6,19 @@ describe PicturehouseUk::Internal::Website do
6
6
  describe '#cinema(id)' do
7
7
  subject { described_class.new.cinema('Duke_Of_Yorks') }
8
8
 
9
- before { stub_get('cinema/Duke_Of_Yorks/', duke_of_yorks_html) }
9
+ before { stub_get('cinema/Duke_Of_Yorks', duke_of_yorks_html) }
10
10
 
11
11
  it 'returns a string' do
12
12
  subject.class.must_equal String
13
13
  end
14
14
  end
15
15
 
16
- describe '#contact_us(id)' do
17
- subject { described_class.new.contact_us('Duke_Of_Yorks') }
16
+ describe '#info(id)' do
17
+ subject { described_class.new.info('Duke_Of_Yorks') }
18
18
 
19
19
  before do
20
20
  stub_get(
21
- 'cinema/Duke_Of_Yorks/Hires_Info/Contact_Us/',
21
+ 'cinema/info/Duke_Of_Yorks',
22
22
  duke_of_yorks_contact_us_html
23
23
  )
24
24
  end
@@ -45,7 +45,7 @@ describe PicturehouseUk::Internal::Website do
45
45
  end
46
46
 
47
47
  def duke_of_yorks_contact_us_html
48
- read_file('../../../../fixtures/contact_us/Duke_Of_Yorks.html')
48
+ read_file('../../../../fixtures/info/Duke_Of_Yorks.html')
49
49
  end
50
50
 
51
51
  def home_html
@@ -57,7 +57,7 @@ describe PicturehouseUk::Internal::Website do
57
57
  end
58
58
 
59
59
  def stub_get(site_path, response_body)
60
- url = "http://www.picturehouses.co.uk/#{site_path}"
60
+ url = "http://www.picturehouses.com/#{site_path}"
61
61
  response = { status: 200, body: response_body, headers: {} }
62
62
  stub_request(:get, url).to_return(response)
63
63
  end
@@ -19,7 +19,15 @@ describe PicturehouseUk::Screening do
19
19
 
20
20
  it 'returns correct number of screenings' do
21
21
  PicturehouseUk::Internal::Website.stub :new, website do
22
- subject.count.must_equal 33
22
+ subject.count.must_equal 59
23
+ end
24
+ end
25
+
26
+ it 'has valid screenings' do
27
+ PicturehouseUk::Internal::Website.stub :new, website do
28
+ subject.map(&:showing_at).each do |time|
29
+ time.wont_equal Time.utc(1970, 1, 1, 0, 0)
30
+ end
23
31
  end
24
32
  end
25
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picturehouse_uk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,29 +127,24 @@ files:
127
127
  - lib/picturehouse_uk.rb
128
128
  - lib/picturehouse_uk/cinema.rb
129
129
  - lib/picturehouse_uk/film.rb
130
- - lib/picturehouse_uk/internal/address_parser.rb
131
- - lib/picturehouse_uk/internal/cinema_page.rb
132
- - lib/picturehouse_uk/internal/film_with_screenings_parser.rb
130
+ - lib/picturehouse_uk/internal/parser/address.rb
131
+ - lib/picturehouse_uk/internal/parser/screenings.rb
133
132
  - lib/picturehouse_uk/internal/title_sanitizer.rb
134
133
  - lib/picturehouse_uk/internal/website.rb
135
134
  - lib/picturehouse_uk/screening.rb
136
135
  - lib/picturehouse_uk/version.rb
137
136
  - picturehouse_uk.gemspec
138
137
  - test/fixture_updater.rb
139
- - test/fixtures/address-fragments/duke-of-yorks.html
140
- - test/fixtures/address-fragments/hackney-picturehouse.html
141
138
  - test/fixtures/cinema/Duke_Of_Yorks.html
142
- - test/fixtures/cinema/Duke_Of_Yorks/film_last.html
143
- - test/fixtures/cinema/Duke_Of_Yorks/film_second.html
144
- - test/fixtures/cinema/York_Picturehouse/basement.html
145
- - test/fixtures/contact_us/Duke_Of_Yorks.html
146
- - test/fixtures/contact_us/Dukes_At_Komedia.html
139
+ - test/fixtures/cinema/Dukes_At_Komedia.html
140
+ - test/fixtures/cinema/Phoenix_Picturehouse.html
147
141
  - test/fixtures/home.html
142
+ - test/fixtures/info/Duke_Of_Yorks.html
143
+ - test/fixtures/info/Dukes_At_Komedia.html
144
+ - test/fixtures/info/Phoenix_Picturehouse.html
148
145
  - test/lib/picturehouse_uk/cinema_test.rb
149
146
  - test/lib/picturehouse_uk/film_test.rb
150
- - test/lib/picturehouse_uk/internal/address_parser_test.rb
151
- - test/lib/picturehouse_uk/internal/cinema_page_test.rb
152
- - test/lib/picturehouse_uk/internal/film_with_screenings_parser_test.rb
147
+ - test/lib/picturehouse_uk/internal/parser/screenings_test.rb
153
148
  - test/lib/picturehouse_uk/internal/title_sanitizer_test.rb
154
149
  - test/lib/picturehouse_uk/internal/website_test.rb
155
150
  - test/lib/picturehouse_uk/screening_test.rb
@@ -182,20 +177,16 @@ specification_version: 4
182
177
  summary: It's a scraper, but a nice one
183
178
  test_files:
184
179
  - test/fixture_updater.rb
185
- - test/fixtures/address-fragments/duke-of-yorks.html
186
- - test/fixtures/address-fragments/hackney-picturehouse.html
187
180
  - test/fixtures/cinema/Duke_Of_Yorks.html
188
- - test/fixtures/cinema/Duke_Of_Yorks/film_last.html
189
- - test/fixtures/cinema/Duke_Of_Yorks/film_second.html
190
- - test/fixtures/cinema/York_Picturehouse/basement.html
191
- - test/fixtures/contact_us/Duke_Of_Yorks.html
192
- - test/fixtures/contact_us/Dukes_At_Komedia.html
181
+ - test/fixtures/cinema/Dukes_At_Komedia.html
182
+ - test/fixtures/cinema/Phoenix_Picturehouse.html
193
183
  - test/fixtures/home.html
184
+ - test/fixtures/info/Duke_Of_Yorks.html
185
+ - test/fixtures/info/Dukes_At_Komedia.html
186
+ - test/fixtures/info/Phoenix_Picturehouse.html
194
187
  - test/lib/picturehouse_uk/cinema_test.rb
195
188
  - test/lib/picturehouse_uk/film_test.rb
196
- - test/lib/picturehouse_uk/internal/address_parser_test.rb
197
- - test/lib/picturehouse_uk/internal/cinema_page_test.rb
198
- - test/lib/picturehouse_uk/internal/film_with_screenings_parser_test.rb
189
+ - test/lib/picturehouse_uk/internal/parser/screenings_test.rb
199
190
  - test/lib/picturehouse_uk/internal/title_sanitizer_test.rb
200
191
  - test/lib/picturehouse_uk/internal/website_test.rb
201
192
  - test/lib/picturehouse_uk/screening_test.rb
@@ -1,72 +0,0 @@
1
- module PicturehouseUk
2
- # @api private
3
- module Internal
4
- # Parses a chunk of HTML to derive address
5
- class AddressParser
6
- # CSS for address lines
7
- ADDRESS_LINES_CSS = '.cinemaListBox'
8
-
9
- # regular expression for postal code
10
- POSTCODE_REGEX = /[A-Z]{1,2}\d{1,2}[A-Z]?\s\d{1,2}[A-Z]{1,2}/
11
-
12
- # @param [String] node the HTML to parse into an address
13
- # @return [PicturehouseUk::Internal::AddressParser]
14
- def initialize(html)
15
- @html = html
16
- end
17
-
18
- # @return [Hash] contains :street_address, :extended_address, :locality,
19
- # :postal_code, :country
20
- # @note Uses the address naming from http://microformats.org/wiki/adr
21
- def address
22
- {
23
- street_address: array[0],
24
- extended_address: array.length > 3 ? array[1] : nil,
25
- locality: array[-2],
26
- postal_code: array[-1],
27
- country: 'United Kingdom'
28
- }
29
- end
30
-
31
- private
32
-
33
- def array
34
- @array ||= begin
35
- if standard?
36
- lines[0..postal_code_index(lines)]
37
- else
38
- # this is a horrendous hack for Hackney Picturehouse
39
- doc.css('p').to_s.split('Box Office')[0].split('<br> ')[1..-1]
40
- end
41
- end
42
- end
43
-
44
- def doc
45
- @doc ||= Nokogiri::HTML(@html)
46
- end
47
-
48
- def matched_lines
49
- @matched_lines ||= begin
50
- matched = doc.css(ADDRESS_LINES_CSS).map { |n| n.children[0].to_s }
51
- matched.reject { |e| e == '' }
52
- end
53
- end
54
-
55
- def postal_code_index(array)
56
- array.index { |element| element.match(POSTCODE_REGEX) }
57
- end
58
-
59
- def lines
60
- if matched_lines.length > 0 && matched_lines[0].match(/\d+\Z/) # komedia
61
- ["#{matched_lines[0]} #{matched_lines[1]}"] + matched_lines[2..-1]
62
- else
63
- matched_lines
64
- end
65
- end
66
-
67
- def standard?
68
- lines && lines.length > 0
69
- end
70
- end
71
- end
72
- end