Class: Strava::Leaderboard

Inherits:
Base
  • Object
show all
Defined in:
lib/strava/leaderboard.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #id, #response

Instance Method Summary collapse

Methods inherited from Base

#detailed?, #initialize, #resource_state, resource_states, #summary?

Constructor Details

This class inherits a constructor from Strava::Base

Instance Method Details

#get_detailsObject



29
30
31
32
33
34
# File 'lib/strava/leaderboard.rb', line 29

def get_details
  return self if detailed?
  res = client.get(path_base).to_h
  update(res)
  res
end

#get_standings(per_page: nil, page: nil, **params) ⇒ Object



36
37
38
39
# File 'lib/strava/leaderboard.rb', line 36

def get_standings(per_page: nil, page: nil, **params)
  res = client.get(path_base, per_page: per_page, page: page, **params).to_h
  update(res)
end

#path_baseObject



41
42
43
# File 'lib/strava/leaderboard.rb', line 41

def path_base
  "segments/#{@segment_id}/leaderboard"
end

#set_ivarsObject

Class to represent Strava Activity https://strava.github.io/api/v3/activities/ Your code goes here...



7
8
9
# File 'lib/strava/leaderboard.rb', line 7

def set_ivars
  @entries      = {}
end

#standingsObject Also known as: entries



11
12
13
# File 'lib/strava/leaderboard.rb', line 11

def standings
  @entries.values.sort { |a, b| a.rank <=> b.rank }
end

#update(data, **opts) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/strava/leaderboard.rb', line 16

def update(data, **opts)
  @response = data
  @segment_id = data['segment_id'] if data['segment_id']

  @entry_count  = data['entry_count'] if data['entry_count']
  if data['entries']
    data['entries'].each { |hash| hash['id'] = hash['effort_id'] }
    parse_data(@entries, data['entries'], klass: LeaderboardEntry, client: @client)
  end

  self
end