Class: GitFit::Parser::FIT
Constant Summary collapse
- FIT_EPOCH =
Time.utc(1989, 12, 31).freeze
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from GitFit::Parser::Base
Instance Method Details
#call(input) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/git_fit/parser/fit.rb', line 10 def call(input) path = input.is_a?(String) ? input : nil return [] unless path && File.exist?(path) records = GitFit::FIT::Decoder.decode(path) return [] if records.empty? points = records.filter_map { |r| record_to_point(r) } return [] if points.empty? times = points.map { |p| p[3] }.compact start_date = times.min end_date = times.max sport_type = GitFit::FIT::Decoder.sport(path) [build_activity_attrs({ run_id: build_run_id("fit", SecureRandom.hex(8)), name: nil, distance: total_distance(points), moving_time: moving_time_from_points(points), elapsed_time: elapsed_time_from_points(points), sport_category: normalize_sport_type(sport_type), sport_type: sport_type, start_date: start_date, start_date_local: start_date, location_country: nil, summary_polyline: simplify_polyline(points.map { |p| [p[0], p[1]] }), average_heartrate: average_heartrate(points), elevation_gain: elevation_gain(points), source: "fit" })] end |