poms 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/poms/fields.rb +8 -162
- data/lib/poms/fields/details.rb +98 -0
- data/lib/poms/fields/media.rb +34 -0
- data/lib/poms/fields/schedule.rb +78 -0
- data/lib/poms/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca74a26e7ddddcefe3cf672fb7a5503f9c89d519
|
4
|
+
data.tar.gz: 26b66cddf53204d26e438fa59f05b9dfa80e8dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ca9b10cc25fa8e2c7ca97bedf79945ddea44d411b19f9fbbb2acf38774ffbccd9053ae2e958c62ce030d248cafc0c2636c0ea1d776218662ca7bc6a4369745d
|
7
|
+
data.tar.gz: fbf4ddc8db109d6d7b2fcea5e3ae7203a9a6d5662290e567e60b22ef57f5e55e24b9a2714f3687bbdd718254f3dc720955051f9f6ec90237771bb0fa5ada607e
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -84,3 +84,7 @@ Gem | API
|
|
84
84
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
85
|
4. Push to the branch (`git push origin my-new-feature`)
|
86
86
|
5. Create new Pull Request
|
87
|
+
|
88
|
+
## Releasing
|
89
|
+
|
90
|
+
Make sure to use [Semantic Versioning](https://semver.org/) when bumping the version. To release tag the master branch with the version and then push to rubygems. `rake release` does this for you.
|
data/lib/poms/fields.rb
CHANGED
@@ -1,167 +1,13 @@
|
|
1
|
-
require 'poms/
|
1
|
+
require 'poms/fields/details'
|
2
|
+
require 'poms/fields/media'
|
3
|
+
require 'poms/fields/schedule'
|
2
4
|
|
3
5
|
module Poms
|
4
|
-
#
|
5
|
-
#
|
6
|
+
# Collection module that import the various field modules to the higher
|
7
|
+
# Poms::Fields level
|
6
8
|
module Fields
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# Returns the title, main by default
|
12
|
-
def title(item, type = 'MAIN')
|
13
|
-
value_of_type(item, 'titles', type)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns the description, main by default
|
17
|
-
def description(item, type = 'MAIN')
|
18
|
-
value_of_type(item, 'descriptions', type)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns all the descendantOfs of the type given.
|
22
|
-
# @param item The Poms Hash
|
23
|
-
# @param type The type of descendantOfs we want
|
24
|
-
def descendants_of(item, type)
|
25
|
-
item['descendantOf'].select { |descendant| descendant['type'] == type }
|
26
|
-
end
|
27
|
-
|
28
|
-
def broadcasters(item)
|
29
|
-
Array(item['broadcasters']).map do |key_value_pair|
|
30
|
-
key_value_pair['value']
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns the images from the hash
|
35
|
-
def images(item)
|
36
|
-
item['images'].try(:sort_by) do |i|
|
37
|
-
image_order_index(i)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Extracts the image id from an image hash
|
42
|
-
# Expects a hash of just an image from POMS
|
43
|
-
def image_id(image)
|
44
|
-
return unless image['imageUri']
|
45
|
-
image['imageUri'].split(':').last
|
46
|
-
end
|
47
|
-
|
48
|
-
def image_order_index(image)
|
49
|
-
IMAGE_TYPE_PRIORITY.index(image['type']) || IMAGE_TYPE_PRIORITY.size
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns the id of the first image or nil if there are none.
|
53
|
-
def first_image_id(item)
|
54
|
-
return unless images(item)
|
55
|
-
image_id(images(item).first)
|
56
|
-
end
|
57
|
-
|
58
|
-
def mid(item)
|
59
|
-
item['mid']
|
60
|
-
end
|
61
|
-
|
62
|
-
# Returns an array of odi stream types.
|
63
|
-
# Note: this code is copied from Broadcast and it is assumed it was working
|
64
|
-
# there.
|
65
|
-
def odi_streams(item)
|
66
|
-
locations = item['locations']
|
67
|
-
return [] if locations.nil? || locations.empty?
|
68
|
-
odi_streams = locations.select { |l| l['programUrl'].match(/^odi/) }
|
69
|
-
streams = odi_streams.map do |l|
|
70
|
-
l['programUrl'].match(%r{^[\w+]+\:\/\/[\w\.]+\/video\/(\w+)\/\w+})[1]
|
71
|
-
end
|
72
|
-
streams.uniq
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns the enddate of the publication of an internet vod if present.
|
76
|
-
def available_until(item)
|
77
|
-
return if item['predictions'].blank?
|
78
|
-
internetvod = item['predictions']
|
79
|
-
.find { |p| p['platform'] == 'INTERNETVOD' }
|
80
|
-
return unless internetvod
|
81
|
-
Timestamp.to_datetime(internetvod['publishStop'])
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns the index at which it is in the parent. When no
|
85
|
-
# :member_of keyword is given, it will return the first found
|
86
|
-
# index. Else, when a parent is found with matching member_of
|
87
|
-
# midref, it returns that index. Else returns nil.
|
88
|
-
# @param item The Poms Hash
|
89
|
-
# @param optional :member_of The midref of parent for which we
|
90
|
-
# seek the index
|
91
|
-
def position(item, member_of: nil)
|
92
|
-
parent(item, midref: member_of).try(:[], 'index')
|
93
|
-
end
|
94
|
-
|
95
|
-
# Finds a parent the data is "member of". If :midref is given, it
|
96
|
-
# will look for the parent that matches that mid and return nil if
|
97
|
-
# not found. Without the :midref it will return the first parent.
|
98
|
-
# @param item The Poms Hash
|
99
|
-
# @param optional midref The midref of parent we seek.
|
100
|
-
def parent(item, midref: nil)
|
101
|
-
if midref
|
102
|
-
parents(item).find { |parent| parent['midRef'] == midref }
|
103
|
-
else
|
104
|
-
parents(item).first
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Returns the parents that the element is member of. Will always
|
109
|
-
# return an array.
|
110
|
-
def parents(item)
|
111
|
-
Array(item['memberOf'])
|
112
|
-
end
|
113
|
-
|
114
|
-
# Returns the NICAM age rating of the item or ALL if no age rating exists
|
115
|
-
def age_rating(item)
|
116
|
-
item.fetch('ageRating', 'ALL')
|
117
|
-
end
|
118
|
-
|
119
|
-
# Returns an array containing zero or more content ratings of the item
|
120
|
-
# Possible content ratings are:
|
121
|
-
# ANGST, DISCRIMINATIE, DRUGS_EN_ALCOHOL, GEWELD, GROF_TAALGEBRUIK and SEKS
|
122
|
-
def content_ratings(item)
|
123
|
-
item.fetch('contentRatings', [])
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns an array of start and end times for the scheduled events for
|
127
|
-
# this item. It returns an empty array if no events are found. You can pass
|
128
|
-
# in a block to filter the events on data that is not returned, like
|
129
|
-
# channel.
|
130
|
-
#
|
131
|
-
# @param item The Poms hash
|
132
|
-
def schedule_events(item)
|
133
|
-
events = item.fetch('scheduleEvents', [])
|
134
|
-
events = yield(events) if block_given?
|
135
|
-
events.map { |event| hash_event(event) }
|
136
|
-
end
|
137
|
-
|
138
|
-
# Turns the event into a hash.
|
139
|
-
def hash_event(event)
|
140
|
-
{
|
141
|
-
'starts_at' => Timestamp.to_datetime(event.fetch('start')),
|
142
|
-
'ends_at' => Timestamp.to_datetime(event.fetch('start') +
|
143
|
-
event.fetch('duration'))
|
144
|
-
}
|
145
|
-
end
|
146
|
-
private_class_method :hash_event
|
147
|
-
|
148
|
-
# Poms has arrays of hashes for some types that have a value and type. This
|
149
|
-
# is a way to access those simply.
|
150
|
-
#
|
151
|
-
# Example:
|
152
|
-
# item = {'titles' => [{'value' => 'Main title', 'type' => 'MAIN'},
|
153
|
-
# {'value' => 'Subtitle', 'type' => 'SUB'}] }
|
154
|
-
# value_of_type(item, 'titles', 'MAIN') => 'Main title'
|
155
|
-
#
|
156
|
-
# @param item The Poms hash
|
157
|
-
# @param key The key of the array we want to look in
|
158
|
-
# @param type The type to select
|
159
|
-
def value_of_type(item, key, type)
|
160
|
-
return unless item && item[key]
|
161
|
-
res = item[key].find { |value| value['type'] == type }
|
162
|
-
return unless res
|
163
|
-
res['value']
|
164
|
-
end
|
165
|
-
private_class_method :value_of_type
|
9
|
+
extend Poms::Fields::Details
|
10
|
+
extend Poms::Fields::Media
|
11
|
+
extend Poms::Fields::Schedule
|
166
12
|
end
|
167
13
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'poms/timestamp'
|
2
|
+
module Poms
|
3
|
+
module Fields
|
4
|
+
# Module to find details from for ex. attributes on poms items.
|
5
|
+
module Details
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Returns the title, main by default
|
9
|
+
def title(item, type = 'MAIN')
|
10
|
+
value_of_type(item, 'titles', type)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the description, main by default
|
14
|
+
def description(item, type = 'MAIN')
|
15
|
+
value_of_type(item, 'descriptions', type)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns all the descendantOfs of the type given.
|
19
|
+
# @param item The Poms Hash
|
20
|
+
# @param type The type of descendantOfs we want
|
21
|
+
def descendants_of(item, type)
|
22
|
+
item['descendantOf'].select { |descendant| descendant['type'] == type }
|
23
|
+
end
|
24
|
+
|
25
|
+
def broadcasters(item)
|
26
|
+
Array(item['broadcasters']).map do |key_value_pair|
|
27
|
+
key_value_pair['value']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def mid(item)
|
32
|
+
item['mid']
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the index at which it is in the parent. When no
|
36
|
+
# :member_of keyword is given, it will return the first found
|
37
|
+
# index. Else, when a parent is found with matching member_of
|
38
|
+
# midref, it returns that index. Else returns nil.
|
39
|
+
# @param item The Poms Hash
|
40
|
+
# @param optional :member_of The midref of parent for which we
|
41
|
+
# seek the index
|
42
|
+
def position(item, member_of: nil)
|
43
|
+
parent(item, midref: member_of).try(:[], 'index')
|
44
|
+
end
|
45
|
+
|
46
|
+
# Finds a parent the data is "member of". If :midref is given, it
|
47
|
+
# will look for the parent that matches that mid and return nil if
|
48
|
+
# not found. Without the :midref it will return the first parent.
|
49
|
+
# @param item The Poms Hash
|
50
|
+
# @param optional midref The midref of parent we seek.
|
51
|
+
def parent(item, midref: nil)
|
52
|
+
if midref
|
53
|
+
parents(item).find { |parent| parent['midRef'] == midref }
|
54
|
+
else
|
55
|
+
parents(item).first
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the parents that the element is member of. Will always
|
60
|
+
# return an array.
|
61
|
+
def parents(item)
|
62
|
+
Array(item['memberOf'])
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns the NICAM age rating of the item or ALL if no age rating exists
|
66
|
+
def age_rating(item)
|
67
|
+
item.fetch('ageRating', 'ALL')
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns an array containing zero or more content ratings of the item
|
71
|
+
# Possible content ratings are:
|
72
|
+
# ANGST, DISCRIMINATIE, DRUGS_EN_ALCOHOL, GEWELD, GROF_TAALGEBRUIK and
|
73
|
+
# SEKS
|
74
|
+
def content_ratings(item)
|
75
|
+
item.fetch('contentRatings', [])
|
76
|
+
end
|
77
|
+
|
78
|
+
# Poms has arrays of hashes for some types that have a value and type.
|
79
|
+
# This is a way to access those simply.
|
80
|
+
#
|
81
|
+
# Example:
|
82
|
+
# item = {'titles' => [{'value' => 'Main title', 'type' => 'MAIN'},
|
83
|
+
# {'value' => 'Subtitle', 'type' => 'SUB'}] }
|
84
|
+
# value_of_type(item, 'titles', 'MAIN') => 'Main title'
|
85
|
+
#
|
86
|
+
# @param item The Poms hash
|
87
|
+
# @param key The key of the array we want to look in
|
88
|
+
# @param type The type to select
|
89
|
+
def value_of_type(item, key, type)
|
90
|
+
return unless item && item[key]
|
91
|
+
res = item[key].find { |value| value['type'] == type }
|
92
|
+
return unless res
|
93
|
+
res['value']
|
94
|
+
end
|
95
|
+
private_class_method :value_of_type
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Poms
|
2
|
+
module Fields
|
3
|
+
# Module to retrieve media related information from poms items.
|
4
|
+
module Media
|
5
|
+
extend self
|
6
|
+
|
7
|
+
IMAGE_TYPE_PRIORITY = %w[PROMO_LANDSCAPE PICTURE].freeze
|
8
|
+
|
9
|
+
# Returns the images from the hash
|
10
|
+
def images(item)
|
11
|
+
item['images'].try(:sort_by) do |i|
|
12
|
+
image_order_index(i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Extracts the image id from an image hash
|
17
|
+
# Expects a hash of just an image from POMS
|
18
|
+
def image_id(image)
|
19
|
+
return unless image['imageUri']
|
20
|
+
image['imageUri'].split(':').last
|
21
|
+
end
|
22
|
+
|
23
|
+
def image_order_index(image)
|
24
|
+
IMAGE_TYPE_PRIORITY.index(image['type']) || IMAGE_TYPE_PRIORITY.size
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the id of the first image or nil if there are none.
|
28
|
+
def first_image_id(item)
|
29
|
+
return unless images(item)
|
30
|
+
image_id(images(item).first)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'poms/timestamp'
|
2
|
+
|
3
|
+
module Poms
|
4
|
+
module Fields
|
5
|
+
# modeule to retrieve scheduling/timtable related information from
|
6
|
+
# poms items.
|
7
|
+
module Schedule
|
8
|
+
extend self
|
9
|
+
|
10
|
+
# Returns an array of odi stream types.
|
11
|
+
# Note: this code is copied from Broadcast
|
12
|
+
# and it is assumed it was working there.
|
13
|
+
def odi_streams(item)
|
14
|
+
locations = item['locations']
|
15
|
+
return [] if locations.nil? || locations.empty?
|
16
|
+
odi_streams = locations.select { |l| l['programUrl'].match(/^odi/) }
|
17
|
+
streams = odi_streams.map do |l|
|
18
|
+
l['programUrl'].match(%r{^[\w+]+\:\/\/[\w\.]+\/video\/(\w+)\/\w+})[1]
|
19
|
+
end
|
20
|
+
streams.uniq
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns an array of start and end times for the scheduled events for
|
24
|
+
# this item. It returns an empty array if no events are found.
|
25
|
+
# You can pass in a block to filter the events on data that is not
|
26
|
+
# returned, like channel.
|
27
|
+
#
|
28
|
+
# @param item The Poms hash
|
29
|
+
def schedule_events(item)
|
30
|
+
events = item.fetch('scheduleEvents', [])
|
31
|
+
events = yield(events) if block_given?
|
32
|
+
events.map { |event| hash_event(event) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the first publication from an items location array which has
|
36
|
+
# INTERNETVOD and is PUBLISHED
|
37
|
+
def publication(poms_item)
|
38
|
+
return if poms_item['locations'].blank?
|
39
|
+
poms_item['locations'].find do |item|
|
40
|
+
item['platform'] == 'INTERNETVOD' && item['workflow'] == 'PUBLISHED'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return the publishStop datetime from a publication
|
45
|
+
def publish_stop(poms_item)
|
46
|
+
published_item = publication(poms_item)
|
47
|
+
return unless published_item
|
48
|
+
Timestamp.to_datetime(published_item['publishStop'])
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return the publishStart datetime from a publication
|
52
|
+
def publish_start(poms_item)
|
53
|
+
published_item = publication(poms_item)
|
54
|
+
return unless published_item
|
55
|
+
Timestamp.to_datetime(published_item['publishStart'])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the enddate of the publication of an internet vod if present.
|
59
|
+
def available_until(item)
|
60
|
+
return if item['predictions'].blank?
|
61
|
+
internetvod = item['predictions']
|
62
|
+
.find { |p| p['platform'] == 'INTERNETVOD' }
|
63
|
+
return unless internetvod
|
64
|
+
Timestamp.to_datetime(internetvod['publishStop'])
|
65
|
+
end
|
66
|
+
|
67
|
+
# Turns the event into a hash.
|
68
|
+
def hash_event(event)
|
69
|
+
{
|
70
|
+
'starts_at' => Timestamp.to_datetime(event.fetch('start')),
|
71
|
+
'ends_at' => Timestamp.to_datetime(event.fetch('start') +
|
72
|
+
event.fetch('duration'))
|
73
|
+
}
|
74
|
+
end
|
75
|
+
private_class_method :hash_event
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/poms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Kruijsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -228,6 +228,9 @@ files:
|
|
228
228
|
- lib/poms/configuration.rb
|
229
229
|
- lib/poms/errors.rb
|
230
230
|
- lib/poms/fields.rb
|
231
|
+
- lib/poms/fields/details.rb
|
232
|
+
- lib/poms/fields/media.rb
|
233
|
+
- lib/poms/fields/schedule.rb
|
231
234
|
- lib/poms/timestamp.rb
|
232
235
|
- lib/poms/version.rb
|
233
236
|
- poms.gemspec
|