Class: Activity
- Inherits:
-
Object
- Object
- Activity
- Defined in:
- lib/strava/activity.rb
Overview
Strava activity model
Instance Attribute Summary collapse
-
#avg_speed ⇒ Object
Returns the value of attribute avg_speed.
-
#date ⇒ Object
Returns the value of attribute date.
-
#distance_km ⇒ Object
Returns the value of attribute distance_km.
-
#elapsed_time_min ⇒ Object
Returns the value of attribute elapsed_time_min.
Instance Method Summary collapse
- #human_avg_speed ⇒ Object
- #human_date ⇒ Object
- #human_distance_km ⇒ Object
- #human_elapsed_time ⇒ Object
-
#initialize(raw_activity) ⇒ Activity
constructor
Initialize an activity from the raw API json from Strava.
Constructor Details
#initialize(raw_activity) ⇒ Activity
Initialize an activity from the raw API json from Strava
raw_activity [Hash]
10 11 12 13 14 15 16 |
# File 'lib/strava/activity.rb', line 10 def initialize(raw_activity) @date = Time.parse(raw_activity.start_date_local) @distance_km = (raw_activity.distance / 1000.0).round(3) @elapsed_time_min = (raw_activity.elapsed_time / 60.0).round(2) elapsed_time_hour = (raw_activity.elapsed_time / 3600.0) @avg_speed = (distance_km / elapsed_time_hour).round(2) end |
Instance Attribute Details
#avg_speed ⇒ Object
Returns the value of attribute avg_speed.
5 6 7 |
# File 'lib/strava/activity.rb', line 5 def avg_speed @avg_speed end |
#date ⇒ Object
Returns the value of attribute date.
5 6 7 |
# File 'lib/strava/activity.rb', line 5 def date @date end |
#distance_km ⇒ Object
Returns the value of attribute distance_km.
5 6 7 |
# File 'lib/strava/activity.rb', line 5 def distance_km @distance_km end |
#elapsed_time_min ⇒ Object
Returns the value of attribute elapsed_time_min.
5 6 7 |
# File 'lib/strava/activity.rb', line 5 def elapsed_time_min @elapsed_time_min end |
Instance Method Details
#human_avg_speed ⇒ Object
30 31 32 |
# File 'lib/strava/activity.rb', line 30 def human_avg_speed "#{avg_speed} km/h" end |
#human_date ⇒ Object
18 19 20 |
# File 'lib/strava/activity.rb', line 18 def human_date date.strftime("%d %h %Y") end |
#human_distance_km ⇒ Object
22 23 24 |
# File 'lib/strava/activity.rb', line 22 def human_distance_km "#{distance_km} km" end |
#human_elapsed_time ⇒ Object
26 27 28 |
# File 'lib/strava/activity.rb', line 26 def human_elapsed_time "#{elapsed_time_min} min" end |