Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.10] - 2026-07-09

### Changed
- Refactor `TrackCalculator`: extract a single `dig_key` helper for symbol/string key access, removing duplicated fallback logic across coordinate, elevation, and time readers (no behavior change)

## [1.9.9] - 2026-06-17

### Changed
Expand Down
17 changes: 8 additions & 9 deletions lib/calcpace/track_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def track_distance(points)
return 0.0 if points.nil? || points.size < 2

total = points.each_cons(2).sum do |a, b|
haversine_distance(fetch_coord(a, :lat), fetch_coord(a, :lon),
fetch_coord(b, :lat), fetch_coord(b, :lon))
haversine_distance(dig_key(a, :lat), dig_key(a, :lon),
dig_key(b, :lat), dig_key(b, :lon))
end

total.round(2)
Expand Down Expand Up @@ -180,25 +180,24 @@ def accumulate_elevation(gain, loss, ele_a, ele_b)
end
end

def fetch_coord(point, key)
def dig_key(point, key)
point[key] || point[key.to_s]
end

def fetch_ele(point)
val = point[:ele] || point['ele']
val&.to_f
dig_key(point, :ele)&.to_f
end

def validate_points_have_time(points)
points.each_with_index do |pt, i|
next if pt[:time] || pt['time']
next if dig_key(pt, :time)

raise ArgumentError, "Point at index #{i} is missing :time key required for splits"
end
end

def point_time(point)
t = point[:time] || point['time']
t = dig_key(point, :time)
t.respond_to?(:to_f) ? t.to_f : t
Comment thread
0jonjo marked this conversation as resolved.
end

Expand Down Expand Up @@ -228,8 +227,8 @@ def collect_splits(points, split_km)
end

def process_segment(point_a, point_b, split_km, state)
segment_km = haversine_distance(fetch_coord(point_a, :lat), fetch_coord(point_a, :lon),
fetch_coord(point_b, :lat), fetch_coord(point_b, :lon))
segment_km = haversine_distance(dig_key(point_a, :lat), dig_key(point_a, :lon),
dig_key(point_b, :lat), dig_key(point_b, :lon))
state[:accumulated_km] += segment_km

while state[:accumulated_km] >= split_km * state[:split_number]
Expand Down
2 changes: 1 addition & 1 deletion lib/calcpace/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Calcpace
VERSION = '1.9.9'
VERSION = '1.9.10'
end
Loading