Class: GitFit::Export::CSV
- Inherits:
-
Object
- Object
- GitFit::Export::CSV
- Defined in:
- lib/git_fit/export/csv.rb
Constant Summary collapse
- HEADERS =
%w[ run_id name distance moving_time elapsed_time sport_category sport_type start_date start_date_local location_country summary_polyline average_heartrate max_heartrate average_cadence max_cadence average_power max_power calories average_temperature average_speed elevation_gain source dedup_group_id ].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(db:, output:, activity_filter: nil) ⇒ CSV
constructor
A new instance of CSV.
Constructor Details
#initialize(db:, output:, activity_filter: nil) ⇒ CSV
Returns a new instance of CSV.
17 18 19 20 21 |
# File 'lib/git_fit/export/csv.rb', line 17 def initialize(db:, output:, activity_filter: nil) @db = db @output = output @activity_filter = activity_filter end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/git_fit/export/csv.rb', line 23 def call run_id_to_group = {} @db[:dedup_group_members].each { |gm| run_id_to_group[gm[:run_id]] = gm[:group_id] } dataset = @db[:activities].order(Sequel.desc(:start_date)) dataset = dataset.where(sport_category: @activity_filter) if @activity_filter count = 0 ::CSV.open(@output, 'w') do |csv| csv << HEADERS dataset.each do |a| row = HEADERS[0...-1].map { |h| a[h.to_sym] } row << run_id_to_group[a[:run_id]] csv << row count += 1 end end count end |