class NikeV2::Metric
Public Class Methods
new(activity, data)
click to toggle source
# File lib/nike_v2/metric.rb, line 4 def initialize(activity, data) @activity = activity @unit = data['intervalUnit'] @type = data ['metricType'] @values = data['values'].collect(&:to_f) self end
Public Instance Methods
duration()
click to toggle source
# File lib/nike_v2/metric.rb, line 38 def duration @values.length.send(@unit.downcase) end
during(start, stop)
click to toggle source
# File lib/nike_v2/metric.rb, line 32 def during(start, stop) start_point = time_to_index(start) duration = time_to_index(stop) - start_point @values[start_point, duration] end
total()
click to toggle source
# File lib/nike_v2/metric.rb, line 20 def total @total ||= values.inject(:+) end
total_during(start, stop, convert_to_local = false)
click to toggle source
# File lib/nike_v2/metric.rb, line 24 def total_during(start, stop, convert_to_local = false) if convert_to_local start = @activity.to_tz(start) stop = @activity.to_tz(stop) end during(start, stop).collect(&:to_f).inject(:+) rescue 0 end
type()
click to toggle source
# File lib/nike_v2/metric.rb, line 12 def type @type end
values()
click to toggle source
# File lib/nike_v2/metric.rb, line 16 def values @values end
Private Instance Methods
time_to_index(time)
click to toggle source
# File lib/nike_v2/metric.rb, line 43 def time_to_index(time) difference = time.to_i - @activity.started_at.to_i difference.s.to.send(@unit.downcase).to_s.to_i end