Module: Strava::Models::Mixins::SportType

Extended by:
ActiveSupport::Concern
Included in:
DetailedActivity, SummaryActivity
Defined in:
lib/strava/models/mixins/sport_type.rb

Overview

Provides sport type handling and sport-specific formatting.

This mixin adds the sport_type property and provides sport-aware formatting for distance and pace. For example, swimming activities display distance in meters and pace per 100m, while other activities use kilometers and pace per km.

Also provides emoji representations for various sport types.

Examples:

Using sport type helpers

activity = client.activity(1234567890)
puts activity.sport_type           # => "Run"
puts activity.distance_s            # => "10.0km" (or "500m" for swim)
puts activity.pace_s                # => "4m30s/km" (or "1m20s/100m" for swim)
puts activity.sport_type_emoji      # => "🏃"

Instance Method Summary collapse

Instance Method Details

#distance_sString?

Returns distance formatted appropriately for the sport type.

Swimming activities display distance in meters, while all other activities use kilometers.

Returns:

  • (String, nil)

    Formatted distance



39
40
41
42
43
44
45
# File 'lib/strava/models/mixins/sport_type.rb', line 39

def distance_s
  if sport_type == 'Swim'
    distance_in_meters_s
  else
    distance_in_kilometers_s
  end
end

#pace_sString?

Returns pace formatted appropriately for the sport type.

Swimming activities display pace per 100 meters, while all other activities use pace per kilometer.

Returns:

  • (String, nil)

    Formatted pace



55
56
57
58
59
60
61
62
# File 'lib/strava/models/mixins/sport_type.rb', line 55

def pace_s
  case sport_type
  when 'Swim'
    pace_per_100_meters_s
  else
    pace_per_kilometer_s
  end
end

#sport_type_emojiString?

Returns an emoji representing the sport type.

Returns:

  • (String, nil)

    Emoji character or nil if no emoji for this sport



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/strava/models/mixins/sport_type.rb', line 69

def sport_type_emoji
  case sport_type
  when 'AlpineSki' then '⛷️'
  when 'BackcountrySki' then '🎿️'
  # when "Canoeing" then ''
  # when "Crossfit" then ''
  # when "Elliptical" then ''
  when 'Golf' then '🏌️'
  # when "Handcycle" then ''
  when 'Hike' then '🥾'
  when 'IceSkate' then ''
  when 'InlineSkate' then "\u{1F6FC}"
  # when "Kayaking" then ''
  # when "Kitesurf" then ''
  when 'MountainBikeRide', 'EMountainBikeRide' then '🚵'
  # when "NordicSki" then ''
  when 'Ride', 'EBikeRide', 'VirtualRide', 'GravelRide' then '🚴'
  when 'RockClimbing' then '🧗'
  # when 'RollerSki' then ''
  when 'Rowing' then '🚣'
  when 'Run', 'VirtualRun', 'TrailRun' then '🏃'
  when 'Sail' then '⛵️'
  when 'Skateboard' then '🛹'
  when 'Snowboard' then '🏂'
  # when 'Snowshoe' then ''
  when 'Soccer' then '⚽️'
  # when 'StairStepper' then ''
  # when 'StandUpPaddling' then ''
  when 'Surfing' then '🏄'
  when 'Swim' then '🏊'
  # when 'Velomobile' then ''
  when 'Walk' then '🚶'
  when 'WeightTraining' then '🏋️'
  when 'Wheelchair' then ''
  # when 'Windsurf' then ''
  # when 'Workout' then ''
  when 'Yoga' then '🧘'
  end
end