cineworld_uk 1.0.3 → 1.0.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 965975013c473f998ec09dc724265a7e96d88e62
4
+ data.tar.gz: d9c259cf94a9b63e7c412e6fb1ee32eead4b7f87
5
+ SHA512:
6
+ metadata.gz: 3f8c6957d9f6caf687d1a13867565c7d8983cfcc5130264bc0d2d38f56e43249ff181fea4185e9369a2abd60ecadb888ba091ca89d118b145ece2726a6c8c962
7
+ data.tar.gz: 6ebb510ad7628f1289daa05f768c48ea0c53eda60ea6ab6377073a073112c743d59c065afee69c6022cde5e98b0a295bb419fa0f3e64ade42fad8dfb53918f44
data/.travis.yml CHANGED
@@ -2,3 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
data/Rakefile CHANGED
@@ -12,4 +12,13 @@ Rake::TestTask.new do |t|
12
12
  t.verbose = true
13
13
  end
14
14
 
15
+ # http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
16
+ task :console do
17
+ require 'irb'
18
+ require 'irb/completion'
19
+ require 'cineworld_uk'
20
+ ARGV.clear
21
+ IRB.start
22
+ end
23
+
15
24
  task :default => :test
@@ -15,40 +15,7 @@ module CineworldUk
15
15
  # The film name
16
16
  # @return [String]
17
17
  def film_name
18
- name = original_name
19
-
20
- # screening types
21
- name = name.gsub 'Take 2 Thursday - ', '' # take 2 thursday
22
- name = name.gsub 'Autism Friendly Screening: ', '' # remove autism friendly
23
-
24
- # bollywood - remove language from film name
25
- name = name.gsub ' (Malayalam)', ''
26
- name = name.gsub ' (Tamil)', ''
27
-
28
- # special screenings
29
- name = name.gsub 'Bolshoi Ballet Live -', 'Bolshoi:' # bolshoi ballet
30
- if name.match /\- NT .+ encore/
31
- name = 'National Theatre: ' + name.gsub(/\- NT .+ encore/, '')
32
- end
33
- name = name.gsub 'MET Opera -', 'Met Opera:' # fill out Met Opera
34
- name = name.gsub 'NT Live:', 'National Theatre:' # National theatre
35
- name = name.gsub 'Royal Ballet Live:', 'Royal Ballet:' # Royal Ballet
36
-
37
- # fill out Royal Opera House
38
- if pure_name_match = name.match(/Royal Opera Live\: (.+) \-.+/)
39
- name = 'Royal Opera House: ' + pure_name_match[1]
40
- end
41
- name = name.gsub 'Royal Opera Live:', 'Royal Opera House:'
42
-
43
- name = name.gsub '(Encore Performance)', '' # remove rsc-style encore
44
- name = name.gsub 'RSC Live:', 'Royal Shakespeare Company:' # globe
45
-
46
- name = name.gsub /\- \d{1,2}\/\d{1,2}\/\d{2,4}/, '' # remove dates
47
- name = name.gsub /\- \d{1,2}\/\d{1,2}\/\d{2,4}/, '' # remove dates
48
- name = name.gsub /\n/, '' # remove newlines
49
- name = name.gsub /\A\s+/, '' # remove leading spaces
50
- name = name.gsub /\s+\z/, '' # remove trailing spaces
51
- name = name.squeeze(' ') # spaces compressed
18
+ NameParser.new(original_name).standardize
52
19
  end
53
20
 
54
21
  # Showings
@@ -0,0 +1,119 @@
1
+ require 'titleize'
2
+
3
+ module CineworldUk
4
+
5
+ # Internal utility classes: Do not use
6
+ # @api private
7
+ module Internal
8
+
9
+ # Parses a string to derive a standardized movie title
10
+ class NameParser
11
+
12
+ attr_reader :original_name
13
+
14
+ def initialize(name)
15
+ @original_name = name
16
+ @name = name
17
+ end
18
+
19
+ # Process the name and return the final string
20
+ # @return [String]
21
+ def standardize
22
+ strip_and_squeeze.
23
+ ampersands_into_text.
24
+ into_ampersand_if_second_to_last.
25
+ remove_indian_languages.
26
+ remove_screening_details.
27
+ replace_non_film_prefix.
28
+ remove_newlines.
29
+ remove_dates.
30
+ title_case
31
+ to_s
32
+ end
33
+
34
+ # The processed name
35
+ # @return [String]
36
+ def to_s
37
+ @name
38
+ end
39
+
40
+ protected
41
+
42
+ def ampersands_into_text
43
+ _replace(/\s(\&|\&)\s/, ' and ')
44
+ self
45
+ end
46
+
47
+ def into_ampersand_if_second_to_last
48
+ _replace(/\s(and)\s(\w+)\z/, ' & \2')
49
+ self
50
+ end
51
+
52
+ def remove_indian_languages
53
+ languages = ['Malayalam', 'Tamil']
54
+
55
+ _remove(/\((#{languages*'|'})\)/i)
56
+ self
57
+ end
58
+
59
+ def remove_screening_details
60
+ _remove 'Take 2 Thursday - '
61
+ _remove 'Autism Friendly Screening: '
62
+ self
63
+ end
64
+
65
+ def remove_dates
66
+ _remove(/\-? \d{1,2}\/\d{1,2}\/\d{2,4}/)
67
+ self
68
+ end
69
+
70
+ def remove_newlines
71
+ _remove(/\n/)
72
+ self
73
+ end
74
+
75
+ def replace_non_film_prefix
76
+ _replace 'Bolshoi Ballet Live -', 'Bolshoi:'
77
+
78
+ @name = 'National Theatre: ' + @name.gsub(/\- NT .+ encore/, '') if @name.match /\- NT .+ encore/
79
+ _replace 'NT Live:', 'National Theatre:'
80
+
81
+ _replace 'MET Opera -', 'Met Opera:'
82
+ _replace 'Royal Ballet Live:', 'Royal Ballet:'
83
+
84
+ # fill out Royal Opera House
85
+ if pure_name_match = @name.match(/Royal Opera Live\: (.+) \-.+/)
86
+ @name = 'Royal Opera House: ' + pure_name_match[1]
87
+ end
88
+ _replace 'Royal Opera Live:', 'Royal Opera House:'
89
+
90
+ _replace 'RSC Live:', 'Royal Shakespeare Company:'
91
+ _remove '(Encore Performance)' # remove rsc-style encore
92
+
93
+ _remove ' Theatre Series' # West End
94
+
95
+ self
96
+ end
97
+
98
+ def strip_and_squeeze
99
+ @name = @name.strip.squeeze(' ')
100
+ self
101
+ end
102
+
103
+ def title_case
104
+ @name = CineworldUk::Internal::Titleize.titleize(@name)
105
+ self
106
+ end
107
+
108
+ private
109
+
110
+ def _remove(match)
111
+ @name = @name.gsub(match, '')
112
+ end
113
+
114
+ def _replace(match, replacement)
115
+ @name = @name.gsub(match, replacement)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,87 @@
1
+ module CineworldUk
2
+
3
+ # Internal utility classes: Do not use
4
+ # @api private
5
+ module Internal
6
+
7
+ # @note Modified from titleize gem
8
+ # https://github.com/granth/titleize
9
+ module Titleize
10
+
11
+ # List of words not to capitalize unless they lead a phrase
12
+ SMALL_WORDS = %w{a an and as at but by en for if in of on or the to via vs vs.}
13
+
14
+ extend self
15
+
16
+ # Capitalizes most words to create a nicer looking title string.
17
+ #
18
+ # The list of "small words" which are not capped comes from
19
+ # the New York Times Manual of Style, plus 'vs'.
20
+ #
21
+ # Also capitalises roman numerals
22
+ #
23
+ # "notes on a scandal" # => "Notes on a Scandal"
24
+ # "ghostbusters ii" # => "Ghostbusters II"
25
+ #
26
+ # @param [String] title a chunk of html
27
+ # @return [String]
28
+ def titleize(title)
29
+ title = title.dup
30
+ title.downcase! unless title[/[[:lower:]]/] # assume all-caps need fixing
31
+
32
+ phrases(title).map do |phrase|
33
+ words = phrase.split
34
+ words.map do |word|
35
+ def word.capitalize
36
+ # like String#capitalize, but it starts with the first letter
37
+ self.sub(/[[:alpha:]].*/) {|subword| subword.capitalize}
38
+ end
39
+
40
+ case word
41
+ when /[[:alpha:]]\.[[:alpha:]]/ # words with dots in, like "example.com"
42
+ word
43
+ when /[-‑]/ # hyphenated word (regular and non-breaking)
44
+ word.split(/([-‑])/).map do |part|
45
+ SMALL_WORDS.include?(part) ? part : part.capitalize
46
+ end.join
47
+ when /^[[:alpha:]].*[[:upper:]]/ # non-first letter capitalized already
48
+ word
49
+ when /^[[:digit:]]/ # first character is a number
50
+ word
51
+ when /^(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/i
52
+ word.upcase
53
+ when words.first, words.last
54
+ word.capitalize
55
+ when *(SMALL_WORDS + SMALL_WORDS.map {|small| small.capitalize })
56
+ word.downcase
57
+ else
58
+ word.capitalize
59
+ end
60
+ end.join(" ")
61
+ end.join(" ")
62
+ end
63
+
64
+ # Splits a title into an array based on punctuation.
65
+ # @param [String] title Film title
66
+ # @return [Array<String>]
67
+ #
68
+ # "simple title" # => ["simple title"]
69
+ # "more complicated: titling" # => ["more complicated:", "titling"]
70
+ # "even more: complicated - titling" # => ["even more:", "complicated -", "titling"]
71
+ def phrases(title)
72
+ phrases = title.scan(/.+?(?:[-:.;?!] |$)/).map {|phrase| phrase.strip }
73
+
74
+ # rejoin phrases that were split on the '.' from a small word
75
+ if phrases.size > 1
76
+ phrases[0..-2].each_with_index do |phrase, index|
77
+ if SMALL_WORDS.include?(phrase.split.last.downcase)
78
+ phrases[index] << " " + phrases.slice!(index + 1)
79
+ end
80
+ end
81
+ end
82
+
83
+ phrases
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for http://www.cineworld.co.uk
2
- # @version 1.0.3
2
+ # @version 1.0.4
3
3
  module CineworldUk
4
4
  # Gem version
5
- VERSION = "1.0.3"
5
+ VERSION = "1.0.4"
6
6
  end
data/lib/cineworld_uk.rb CHANGED
@@ -6,6 +6,8 @@ require 'tzinfo/data'
6
6
  require_relative './cineworld_uk/version'
7
7
 
8
8
  require_relative './cineworld_uk/internal/film_with_screenings_parser'
9
+ require_relative './cineworld_uk/internal/name_parser'
10
+ require_relative './cineworld_uk/internal/titleize'
9
11
 
10
12
  require_relative './cineworld_uk/cinema'
11
13
  require_relative './cineworld_uk/film'
@@ -12,102 +12,6 @@ describe CineworldUk::Internal::FilmWithScreeningsParser do
12
12
  subject.must_equal('Gravity')
13
13
  end
14
14
  end
15
-
16
- describe 'passed valid film html with take 2 name prefix' do
17
- let(:film_html) { read_film_html('brighton/take-2-thursday-about-time') }
18
-
19
- it 'returns the film name' do
20
- subject.must_equal('About Time')
21
- end
22
- end
23
-
24
- describe 'passed valid film html with autism friendly name prefix' do
25
- let(:film_html) { read_film_html('brighton/autism-friendly-cloudy-2') }
26
-
27
- it 'returns the film name' do
28
- subject.must_equal('Cloudy With A Chance Of Meatballs 2')
29
- end
30
- end
31
-
32
- describe 'passed valid film html with malayalam language suffix' do
33
- let(:film_html) { read_film_html('brighton/geethanjali-malayalam') }
34
-
35
- it 'returns the film name' do
36
- subject.must_equal('Geethanjali')
37
- end
38
- end
39
-
40
- describe 'passed valid film html with tamil language suffix' do
41
- let(:film_html) { read_film_html('wandsworth/arrambam-tamil') }
42
-
43
- it 'returns the film name' do
44
- subject.must_equal('Arrambam')
45
- end
46
- end
47
-
48
- describe 'passed valid film html with bolshoi live' do
49
- let(:film_html) { read_film_html('wandsworth/bolshoi-ballet-live-lost-illusions') }
50
-
51
- it 'returns the film name' do
52
- subject.must_equal('Bolshoi: Lost Illusions')
53
- end
54
- end
55
-
56
- describe 'passed valid film html with NT 50th encore' do
57
- let(:film_html) { read_film_html('wandsworth/frankenstein-nt-50th') }
58
-
59
- it 'returns the film name' do
60
- subject.must_equal('National Theatre: Frankenstein (with Jonny Lee Miller as the Creature)')
61
- end
62
- end
63
-
64
- describe 'passed valid film html with met opera and date' do
65
- let(:film_html) { read_film_html('wandsworth/met-opera-falstaff') }
66
-
67
- it 'returns the film name' do
68
- subject.must_equal('Met Opera: Falstaff')
69
- end
70
- end
71
-
72
- describe 'passed valid film html with nt live' do
73
- let(:film_html) { read_film_html('wandsworth/nt-live-war-horse') }
74
-
75
- it 'returns the film name' do
76
- subject.must_equal('National Theatre: War Horse')
77
- end
78
- end
79
-
80
- describe 'passed valid film html with ballet live' do
81
- let(:film_html) { read_film_html('wandsworth/royal-ballet-live-the-sleeping-beauty') }
82
-
83
- it 'returns the film name' do
84
- subject.must_equal('Royal Ballet: The Sleeping Beauty')
85
- end
86
- end
87
-
88
- describe 'passed valid film html with royal opera house and weird date' do
89
- let(:film_html) { read_film_html('wandsworth/royal-opera-live-parsifal-weird-date') }
90
-
91
- it 'returns the film name' do
92
- subject.must_equal('Royal Opera House: Parsifal')
93
- end
94
- end
95
-
96
- describe 'passed valid film html with RSC and encore' do
97
- let(:film_html) { read_film_html('wandsworth/rsc-live-richard-ii-encore') }
98
-
99
- it 'returns the film name' do
100
- subject.must_equal('Royal Shakespeare Company: Richard II')
101
- end
102
- end
103
-
104
- describe 'passed valid film html with West End Theatre' do
105
- let(:film_html) { read_film_html('wandsworth/west-end-theatre-series-private-lives') }
106
-
107
- it 'returns the film name' do
108
- subject.must_equal("West End Theatre Series: Noel Coward's Private Lives")
109
- end
110
- end
111
15
  end
112
16
 
113
17
  describe '#showings' do
@@ -0,0 +1,42 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe CineworldUk::Internal::NameParser do
4
+
5
+ describe '#standardize' do
6
+ subject { CineworldUk::Internal::NameParser.new(film_name).standardize }
7
+
8
+ [
9
+ ['Rita, Sue and Bob Too', 'Rita, Sue and Bob Too', 'words with "and"'],
10
+ ['Rita, Sue & Bob Too', 'Rita, Sue and Bob Too', 'words with "&"'],
11
+ ['Rita, Sue &amp; Bob Too', 'Rita, Sue and Bob Too', 'words with HTML "&"'],
12
+ ['Cowboys and Aliens', 'Cowboys & Aliens', '"and" as the last but one word'],
13
+ ['Cowboys &amp; Aliens', 'Cowboys & Aliens', 'HTML "&" as the last but one word'],
14
+ ['star wars: episode IV - A new hope', 'Star Wars: Episode IV - A New Hope', 'titleize'],
15
+ ['star wars: episode v - the empire strikes back', 'Star Wars: Episode V - The Empire Strikes Back', 'titleize'],
16
+ ['2 fast 2 furious', '2 Fast 2 Furious', 'titleize'],
17
+ ['Geethanjali (Malayalam)', 'Geethanjali', 'Indian language removal'],
18
+ ['Arrambam (Tamil)', 'Arrambam', 'Indian language removal'],
19
+ ['Take 2 Thursday - About Time', 'About Time', 'remove "Take 2" prefix'],
20
+ ['Autism Friendly Screening: Cloudy With A Chance Of Meatballs 2', 'Cloudy With a Chance of Meatballs 2', 'autism friendly'],
21
+ ['Bolshoi Ballet Live - Lost Illusions', 'Bolshoi: Lost Illusions', 'bolshoi'],
22
+ ['NT Live: War Horse', 'National Theatre: War Horse', 'NT'],
23
+ ['Frankenstein (with Jonny Lee Miller as the Creature) - NT 50th Anniversary encore', 'National Theatre: Frankenstein (With Jonny Lee Miller as the Creature)', 'NT 50th'],
24
+ ['MET Opera - Falstaff - 14/12/2013', 'Met Opera: Falstaff', 'Met Opera with date'],
25
+ ['Royal Ballet Live: The Sleeping Beauty - 19/03/14', 'Royal Ballet: The Sleeping Beauty', 'royal ballet'],
26
+ ['Royal Opera Live: Parsifal - Wednesday 18 Dec 2013', 'Royal Opera House: Parsifal', 'royal opera'],
27
+ ['RSC Live: Richard II (Encore Performance)', 'Royal Shakespeare Company: Richard II', 'rsc'],
28
+ ["West End Theatre Series: Noel Coward's Private Lives", "West End: Noel Coward's Private Lives", 'west end'],
29
+ ["Raiders of\n the Lost Ark", 'Raiders of the Lost Ark', 'New lines']
30
+
31
+ ].each do |test_case|
32
+
33
+ describe test_case[2] do
34
+ let(:film_name) { test_case[0] }
35
+ it 'returns standardized title' do
36
+ subject.must_equal test_case[1]
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe CineworldUk::Internal::Titleize do
4
+
5
+ describe '#titleize(name)' do
6
+ subject { CineworldUk::Internal::Titleize.titleize(string) }
7
+
8
+ [
9
+ ['star wars: episode iv - a new hope', 'Star Wars: Episode IV - A New Hope'],
10
+ ['star wars: episode v - the empire strikes back', 'Star Wars: Episode V - The Empire Strikes Back'],
11
+ ['2 fast 2 furious', '2 Fast 2 Furious'],
12
+ ['saw iv', 'Saw IV'],
13
+ ['fast & Furious 6', 'Fast & Furious 6'],
14
+ ['fast & Furious vi', 'Fast & Furious VI']
15
+ ].each do |test_case|
16
+
17
+ describe test_case[2] do
18
+ let(:string) { test_case[0] }
19
+ it 'returns titlecase' do
20
+ subject.must_equal test_case[1]
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ describe '#phrases(name)' do
28
+ subject { CineworldUk::Internal::Titleize.phrases(string) }
29
+
30
+ [
31
+ ['star wars: episode iv - a new hope',['star wars:','episode iv -','a new hope']],
32
+ ].each do |test_case|
33
+
34
+ describe test_case[0] do
35
+ let(:string) { test_case[0] }
36
+ it 'splits the name' do
37
+ subject.must_equal test_case[1]
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end