odeon_uk 1.1.2 → 1.1.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 +8 -8
- data/lib/odeon_uk/cinema.rb +52 -83
- data/lib/odeon_uk/film.rb +17 -22
- data/lib/odeon_uk/internal/film_with_screenings_parser.rb +15 -1
- data/lib/odeon_uk/screening.rb +13 -15
- data/lib/odeon_uk/version.rb +4 -1
- data/lib/odeon_uk.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDQxYWI5ZWRlNDQ1YThkYjc2NzU5MWJlNTA5ZTM3MGQyMzE3ZDVhOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGRjMjg4Y2M5YTMxZDU5MWQ2ZDIxZTUyMDAyODk3ZWFlZDcwODdmOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjQ0ZGEzOTAwNzczOWVkZmY1NjkzODYyYThiMWQ4NGYxNjMzOWUxOGEzYzAw
|
10
|
+
YzQwYzE3YzQ4ZmJhZWU2MTdmMWI2ZjZmMjUxZDQ0OTA1MWY5N2VkMDVlZjMz
|
11
|
+
ZjNlYzdjOTdhNzk2M2NmYWMzYmIwZTVhMjBkODcyMTJkYTEyOTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjdmNWExNzI5NWJhYTg4YjQzOTdkMTRkYjQ5ZjVjNzMyOTM2YWM3NTY5M2Vk
|
14
|
+
ZmNhYTVmZTdhMmZhNWU1M2JjZTRiYzA4YWMzZDFhY2Q5MzYyMTZmNWIxMTlk
|
15
|
+
YjYyODFjMWNiNzZlZWQ2OWQxMjRhZGUyOTM2OWQ3MGU1OTJmMTQ=
|
data/lib/odeon_uk/cinema.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module OdeonUk
|
2
2
|
|
3
|
-
#
|
3
|
+
# The object representing a cinema on the Odeon UK website
|
4
4
|
class Cinema
|
5
5
|
|
6
|
-
#
|
6
|
+
# @return [String] the brand of the cinema
|
7
7
|
attr_reader :brand
|
8
|
-
#
|
8
|
+
# @return [Integer] the numeric id of the cinema on the Odeon website
|
9
9
|
attr_reader :id
|
10
|
-
#
|
10
|
+
# @return [String] the name of the cinema
|
11
11
|
attr_reader :name
|
12
|
-
#
|
12
|
+
# @return [String] the slug of the cinema
|
13
13
|
attr_reader :slug
|
14
|
-
#
|
14
|
+
# @return [String] the url of the cinema on the Odeon website
|
15
15
|
attr_reader :url
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# url - String of cinema url on the odeon website
|
17
|
+
# @param [Integer, String] id cinema id
|
18
|
+
# @param [String] name cinema name
|
19
|
+
# @param [String] url url on Odeon website
|
20
|
+
# @return [OdeonUk::Cinema]
|
22
21
|
def initialize(id, name, url)
|
23
22
|
@brand = 'Odeon'
|
24
23
|
@id = id.to_i
|
@@ -27,31 +26,23 @@ module OdeonUk
|
|
27
26
|
@url = (url[0] == '/') ? "http://www.odeon.co.uk#{url}" : url
|
28
27
|
end
|
29
28
|
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
29
|
+
# Return basic cinema information for all cinemas
|
30
|
+
# @return [Array<OdeonUk::Cinema>]
|
31
|
+
# @example
|
34
32
|
# OdeonUk::Cinema.all
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# Returns an array of hashes of cinema information.
|
33
|
+
# #=> [<OdeonUk::Cinema brand="Odeon" name="Odeon Tunbridge Wells" slug="odeon-tunbridge-wells" id=23 url="...">, #=> <OdeonUk::Cinema brand="Odeon" name="Odeon Brighton" slug="odeon-brighton" chain_id="71" url="...">, ...]
|
38
34
|
def self.all
|
39
35
|
cinema_links.map do |link|
|
40
36
|
new_from_link link
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# Examples
|
50
|
-
#
|
40
|
+
# Find a single cinema
|
41
|
+
# @param [Integer, String] id the cinema id of the format 71/'71' as used on the odeon.co.uk website
|
42
|
+
# @return [OdeonUk::Cinema, nil]
|
43
|
+
# @example
|
51
44
|
# OdeonUk::Cinema.find('71')
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# Returns an Odeon::Cinema or nil if none was found
|
45
|
+
# #=> <OdeonUk::Cinema brand="Odeon" name="Brighton" slug="brighton" id=71 url="...">
|
55
46
|
def self.find(id)
|
56
47
|
id = id.to_i
|
57
48
|
return nil unless id > 0
|
@@ -59,18 +50,12 @@ module OdeonUk
|
|
59
50
|
all.select { |cinema| cinema.id == id }[0]
|
60
51
|
end
|
61
52
|
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
53
|
+
# Address of the cinema
|
54
|
+
# @return [Hash] of different address parts
|
55
|
+
# @example
|
66
56
|
# cinema = OdeonUk::Cinema.find('71')
|
67
57
|
# cinema.adr
|
68
|
-
#
|
69
|
-
# locality: 'Brighton',
|
70
|
-
# postal_code: 'BN1 2RE',
|
71
|
-
# country_name: 'United Kingdom' }
|
72
|
-
#
|
73
|
-
# Returns an array of strings or nil
|
58
|
+
# #=> { street_address: 'Kingswest', locality: 'Brighton', postal_code: 'BN1 2RE', country_name: 'United Kingdom' }
|
74
59
|
def adr
|
75
60
|
{
|
76
61
|
street_address: street_address,
|
@@ -80,15 +65,12 @@ module OdeonUk
|
|
80
65
|
}
|
81
66
|
end
|
82
67
|
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
68
|
+
# Films with showings scheduled at this cinema
|
69
|
+
# @return [Array<OdeonUk::Film>]
|
70
|
+
# @example
|
87
71
|
# cinema = OdeonUk::Cinema.find('71')
|
88
72
|
# cinema.films
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# Returns an array of Odeon::Film objects
|
73
|
+
# #=> [<OdeonUk::Film name="Iron Man 3">, <OdeonUk::Film name="Star Trek Into Darkness">]
|
92
74
|
def films
|
93
75
|
film_nodes.map do |node|
|
94
76
|
parser = OdeonUk::Internal::FilmWithScreeningsParser.new node.to_s
|
@@ -96,42 +78,33 @@ module OdeonUk
|
|
96
78
|
end.uniq
|
97
79
|
end
|
98
80
|
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
81
|
+
# The locality (town) of the cinema
|
82
|
+
# @return [String]
|
83
|
+
# @example
|
103
84
|
# cinema = OdeonUk::Cinema.find('71')
|
104
85
|
# cinema.locality
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# Returns a String
|
86
|
+
# #=> 'Brighton'
|
108
87
|
def locality
|
109
88
|
address_node.text.match(/\w+(\s\w+){0,}\s+(\w+(\s\w+){0,})/)[2]
|
110
89
|
end
|
111
90
|
|
112
91
|
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
92
|
+
# Post code of the cinema
|
93
|
+
# @return [String]
|
94
|
+
# @example
|
117
95
|
# cinema = OdeonUk::Cinema.find('71')
|
118
96
|
# cinema.postal_code
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# Returns a String
|
97
|
+
# #=> 'BN1 2RE'
|
122
98
|
def postal_code
|
123
99
|
address_node.text.match(/[A-Z]{1,2}\d{1,2}[A-Z]?\s\d{1,2}[A-Z]{1,2}/)[0]
|
124
100
|
end
|
125
101
|
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
102
|
+
# All planned screenings
|
103
|
+
# @return [Array<OdeonUk::Screening>]
|
104
|
+
# @example
|
130
105
|
# cinema = OdeonUk::Cinema.find('71')
|
131
106
|
# cinema.screenings
|
132
|
-
#
|
133
|
-
#
|
134
|
-
# Returns an array of Odeon::Screening objects
|
107
|
+
# #=> [<OdeonUk::Screening film_name="Iron Man 3" cinema_name="Brighton" when="..." varient="...">, <OdeonUk::Screening ...>]
|
135
108
|
def screenings
|
136
109
|
film_nodes.map do |node|
|
137
110
|
parser = OdeonUk::Internal::FilmWithScreeningsParser.new node.to_s
|
@@ -143,31 +116,27 @@ module OdeonUk
|
|
143
116
|
end.flatten
|
144
117
|
end
|
145
118
|
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
119
|
+
# Screenings for particular film
|
120
|
+
# @param [OdeonUk::Film, String] film a film object or title of the film
|
121
|
+
# @return [Array<Odeon::Screening>]
|
122
|
+
# @example
|
150
123
|
# cinema = OdeonUk::Cinema.find('71')
|
151
|
-
# cinema.screenings_of
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
# Returns an array of Odeon::Screening objects
|
124
|
+
# cinema.screenings_of('Iron Man 3')
|
125
|
+
# #=> [<OdeonUk::Screening film_name="Iron Man 3" cinema_name="Brighton" when="..." varient="...">, <OdeonUk::Screening ...>]
|
126
|
+
# iron_man_3 = OdeonUk::Film.new "Iron Man 3"
|
127
|
+
# cinema.screenings_of(iron_man_3)
|
128
|
+
# #=> [<OdeonUk::Screening film_name="Iron Man 3" cinema_name="Brighton" when="..." varient="...">, <OdeonUk::Screening ...>]
|
157
129
|
def screenings_of film
|
158
130
|
film_name = (film.is_a?(OdeonUk::Film) ? film.name : film)
|
159
131
|
screenings.select { |s| s.film_name == film_name }
|
160
132
|
end
|
161
133
|
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
134
|
+
# The street adress of the cinema
|
135
|
+
# @return a String
|
136
|
+
# @example
|
166
137
|
# cinema = OdeonUk::Cinema.find('71')
|
167
138
|
# cinema.street_address
|
168
|
-
#
|
169
|
-
#
|
170
|
-
# Returns a String
|
139
|
+
# #=> 'Kingswest'
|
171
140
|
def street_address
|
172
141
|
address_node.text.match(/\A\s+(\w+(\s\w+){0,})/)[1]
|
173
142
|
end
|
data/lib/odeon_uk/film.rb
CHANGED
@@ -1,50 +1,45 @@
|
|
1
1
|
module OdeonUk
|
2
2
|
|
3
|
-
#
|
3
|
+
# The object representing a film on the Odeon UK website
|
4
4
|
class Film
|
5
5
|
include Comparable
|
6
6
|
|
7
|
-
#
|
7
|
+
# @return [String] the name of the film
|
8
8
|
attr_reader :name
|
9
|
-
#
|
9
|
+
# @return [String] the normalized slug derived from the film name
|
10
10
|
attr_reader :slug
|
11
11
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# name - String of the film name
|
12
|
+
# @param [String] name the film name
|
13
|
+
# @return [OdeonUk::Film]
|
15
14
|
def initialize(name)
|
16
15
|
@name = name
|
17
16
|
@slug = name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-')
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
19
|
+
# Allows sort on objects
|
20
|
+
# @param [OdeonUk::Film] other another film object
|
21
|
+
# @return [Integer] -1, 0 or 1
|
21
22
|
def <=> other
|
22
23
|
self.slug <=> other.slug
|
23
24
|
end
|
24
25
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# True if both objects are the same exact object, or if
|
28
|
-
# type and share an equal slug
|
29
|
-
#
|
30
|
-
# Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/
|
31
|
-
#
|
32
|
-
# object - object to be compared
|
33
|
-
#
|
34
|
-
# Returns Boolean
|
26
|
+
# Check an object is the same as another object.
|
27
|
+
# @param [OdeonUk::Film] other another film
|
28
|
+
# @return [Boolean] True if both objects are the same exact object, or if
|
29
|
+
# they are of the same type and share an equal slug
|
30
|
+
# @note Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/
|
35
31
|
def eql? other
|
36
32
|
self.class == other.class && self == other
|
37
33
|
end
|
38
34
|
|
39
|
-
#
|
40
|
-
#
|
35
|
+
# Generates hash of slug in order to allow two records of the same type and
|
36
|
+
# id to work with something like:
|
41
37
|
#
|
42
38
|
# [ Film.new('ABC'), Film.new('DEF') ] & [ Film.new('DEF'), Film.new('GHI') ]
|
43
39
|
# #=> [ Film.new('DEF') ]
|
44
40
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# Returns an Integer hash of the slug
|
41
|
+
# @return [Integer] hash of slug
|
42
|
+
# @note Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/
|
48
43
|
def hash
|
49
44
|
self.slug.hash
|
50
45
|
end
|
@@ -1,12 +1,19 @@
|
|
1
1
|
module OdeonUk
|
2
|
+
|
3
|
+
# Internal utility classes: Do not use
|
4
|
+
# @api private
|
2
5
|
module Internal
|
3
|
-
|
6
|
+
|
7
|
+
# Parses a chunk of HTML to derive movie showing data
|
4
8
|
class FilmWithScreeningsParser
|
5
9
|
|
10
|
+
# @param [String] film_html a chunk of html
|
6
11
|
def initialize(film_html)
|
7
12
|
@nokogiri_html = Nokogiri::HTML(film_html)
|
8
13
|
end
|
9
14
|
|
15
|
+
# The film name
|
16
|
+
# @return [String]
|
10
17
|
def film_name
|
11
18
|
name = @nokogiri_html.css('.presentation-info h4 a').children.first.to_s
|
12
19
|
|
@@ -34,6 +41,13 @@ module OdeonUk
|
|
34
41
|
name = name.gsub /\s+\z/, '' # remove trailing spaces
|
35
42
|
end
|
36
43
|
|
44
|
+
# Showings
|
45
|
+
# @return [Hash]
|
46
|
+
# @example
|
47
|
+
# {
|
48
|
+
# "2D" => [[Time.utc, 'http://www...'], [Time.utc, 'http://www...']],
|
49
|
+
# "3D" => [[Time.utc, 'http://www...']]
|
50
|
+
# }
|
37
51
|
def showings
|
38
52
|
tz = TZInfo::Timezone.get('Europe/London')
|
39
53
|
@nokogiri_html.css('.times-all.accordion-group').inject({}) do |result, varient_node|
|
data/lib/odeon_uk/screening.rb
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
module OdeonUk
|
2
2
|
|
3
|
-
#
|
3
|
+
# The object representing a single screening of a film on the Odeon UK website
|
4
4
|
class Screening
|
5
5
|
|
6
|
-
#
|
6
|
+
# @return [String] the booking URL on the cinema website
|
7
7
|
attr_reader :booking_url
|
8
|
-
#
|
8
|
+
# @return [String] the cinema name
|
9
9
|
attr_reader :cinema_name
|
10
|
-
#
|
10
|
+
# @return [String] the film name
|
11
11
|
attr_reader :film_name
|
12
|
-
#
|
12
|
+
# @return [Time] the UTC time of the screening
|
13
13
|
attr_reader :when
|
14
|
-
#
|
14
|
+
# @return [String] the type of screening (2D, 3D, IMAX...)
|
15
15
|
attr_reader :varient
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# varient - String representing the type of showing (e.g. 3d/baby/live)
|
17
|
+
# @param [String] film_name the film name
|
18
|
+
# @param [String] the cinema name
|
19
|
+
# @param [Time] time datetime of the screening (UTC preferred)
|
20
|
+
# @param [String] booking_url direct link to the booking page for this screening
|
21
|
+
# @param [String] varient the type of showing (e.g. 3d/baby/live)
|
23
22
|
def initialize(film_name, cinema_name, time, booking_url=nil, varient=nil)
|
24
23
|
@cinema_name, @film_name, @varient = cinema_name, film_name, varient
|
25
24
|
@booking_url = booking_url
|
26
25
|
@when = time.utc? ? time : TZInfo::Timezone.get('Europe/London').local_to_utc(time)
|
27
26
|
end
|
28
27
|
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# Returns a Date
|
28
|
+
# The date of the screening
|
29
|
+
# @return [Date]
|
32
30
|
def date
|
33
31
|
@when.to_date
|
34
32
|
end
|
data/lib/odeon_uk/version.rb
CHANGED
data/lib/odeon_uk.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odeon_uk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Croll
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|