Class: Jumbotron::Deserializers::Public::ScheduleGroups

Inherits:
CommandTower::Deserializers::ApplicationDeserializer
  • Object
show all
Defined in:
app/deserializers/jumbotron/deserializers/public/schedule_groups.rb

Instance Method Summary collapse

Instance Method Details

#call(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/deserializers/jumbotron/deserializers/public/schedule_groups.rb', line 7

def call(params)
  values = {}
  %i[league_id sport league season_id season season_phase kind].each do |key|
    raw = unwrap(fetch_param(params, key))
    return raw if deserializer_result?(raw)

    values[key] = raw
  end

  league_id = optional_positive_integer(values[:league_id], "league_id")
  return league_id if deserializer_result?(league_id)

  season_id = optional_positive_integer(values[:season_id], "season_id")
  return season_id if deserializer_result?(season_id)

  sport = optional_name(values[:sport])
  return sport if deserializer_result?(sport)

  league = optional_name(values[:league])
  return league if deserializer_result?(league)

  season = optional_name(values[:season])
  return season if deserializer_result?(season)

  season_phase = optional_name(values[:season_phase])
  return season_phase if deserializer_result?(season_phase)

  kind = optional_name(values[:kind])
  return kind if deserializer_result?(kind)

  request = Jumbotron::Public::ScheduleGroupsRequest.new(
    league_id: league_id,
    sport: sport,
    league: league,
    season_id: season_id,
    season: season,
    season_phase: season_phase,
    kind: kind
  )
  error = validate_modes(request)
  return error if error

  success(request)
end