Skip to content

Commit 979136e

Browse files
committed
rubocop placations
1 parent 3c2c068 commit 979136e

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

lib/base_shuffle.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class BaseShuffle
77
# @param [Screen] screen Screen showing the content.
88
# @param [Field] field Field showing the content.
99
# @param [Array<Subscription>] subscriptions All the subscriptions to use.
10-
# @param [Hash] options Any additional options.
11-
def initialize(screen, field, subscriptions, options={})
10+
# @param [Hash] options Any additional options.
11+
def initialize(screen, field, subscriptions, options = {})
1212
@screen = screen
1313
@field = field
1414
@subscriptions = subscriptions
@@ -18,13 +18,13 @@ def initialize(screen, field, subscriptions, options={})
1818
# Return the next set content to be shown.
1919
#
2020
# @return [Array<Content>] Next content that should be rendered.
21-
def next_contents()
21+
def next_contents
2222
content.to_a.compact
2323
end
2424

2525
private
2626

2727
def content
28-
@subscriptions.collect{|s| s.contents }.flatten
28+
@subscriptions.collect(&:contents).flatten
2929
end
3030
end

lib/strict_priority_shuffle.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
require 'base_shuffle'
22

33
# Weight and shuffle the content.
4-
# Uses a weighting and shuffling approach similiar to Concerto 1,
5-
# where content is added N times for the weight of each subscription
6-
# then jumbled up and served from a timeline.
4+
# includes only content belonging to the highest weighted subscription
75
class StrictPriorityShuffle < BaseShuffle
8-
9-
def next_contents()
6+
def next_contents
107
prioritised_content.to_a.compact
118
end
129

1310
private
1411

1512
def prioritised_content
16-
highest_prio=@subscriptions.select{|s| s.contents.length>0}.max_by{|s| s.weight}.weight
17-
@subscriptions.select{|s| s.weight==highest_prio}.collect{|s| s.contents}.flatten.shuffle
13+
highest_priority = @subscriptions.select { |s| s.contents.present? }.max_by(&:weight).weight
14+
@subscriptions.select { |s| s.weight == highest_priority }.collect(&:contents).flatten.shuffle
1815
end
1916
end

lib/weighted_shuffle.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
# where content is added N times for the weight of each subscription
66
# then jumbled up and served from a timeline.
77
class WeightedShuffle < BaseShuffle
8-
9-
def next_contents()
8+
def next_contents
109
weighted_content.to_a.compact
1110
end
1211

1312
private
1413

1514
def weighted_content
16-
@subscriptions.collect{|s| s.contents * (!s.weight.nil? ? s.weight : 1)}.flatten.shuffle!
15+
@subscriptions.collect { |s| s.contents * (!s.weight.nil? ? s.weight : 1) }.flatten.shuffle!
1716
end
1817
end

0 commit comments

Comments
 (0)