Class: Wiq::SeasonResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/wiq/season_resolver.rb

Overview

Translates ‘–season <year>` into a set of PaidSession ids. No first-class Season exists in WIQ; we approximate by finding paid sessions whose

start_at, end_at

window overlaps the calendar year.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SeasonResolver

Returns a new instance of SeasonResolver.



8
9
10
# File 'lib/wiq/season_resolver.rb', line 8

def initialize(client)
  @client = client
end

Instance Method Details

#filter_rosters_by_ids(rosters, ids) ⇒ Object

Filter an array of rosters (as returned by /api/v1/rosters) to those whose roster_syncers point at any paid session id in ‘ids`.



36
37
38
39
40
41
42
# File 'lib/wiq/season_resolver.rb', line 36

def filter_rosters_by_ids(rosters, ids)
  id_set = ids.to_set
  rosters.select do |roster|
    syncers = roster["roster_syncers"] || []
    syncers.any? { |rs| id_set.include?(rs["paid_session_id"]) }
  end
end


30
31
32
# File 'lib/wiq/season_resolver.rb', line 30

def paid_session_ids_for(year)
  paid_sessions_for(year).map { |ps| ps["id"] }
end

Returns the array of paid_session hashes that overlap ‘year`.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wiq/season_resolver.rb', line 13

def paid_sessions_for(year)
  year = Integer(year)
  start_of_year = "#{year}-01-01"
  end_of_year = "#{year}-12-31"

  sessions, = @client.collect_all(
    "/api/v1/paid_sessions",
    {
      "q[start_at_lteq]" => end_of_year,
      "q[end_at_gteq]" => start_of_year,
      "per_page" => 100
    },
    key: "paid_sessions"
  )
  sessions
end