dawarich/app/services/own_tracks/rec_parser.rb

22 lines
498 B
Ruby
Raw Normal View History

2024-10-15 16:30:16 -04:00
# frozen_string_literal: true
class OwnTracks::RecParser
attr_reader :file
def initialize(file)
@file = file
2024-10-15 16:30:16 -04:00
end
def call
file.split("\n").map do |line|
2025-07-21 12:59:13 -04:00
# Try tab-separated first, then fall back to whitespace-separated
parts = line.split("\t")
2025-07-21 12:59:13 -04:00
# If tab splitting didn't work (only 1 part), try whitespace splitting
parts = line.split(/\s+/) if parts.size == 1
Oj.load(parts[2]) if parts.size > 2 && parts[1].strip == '*'
end.compact
2024-10-15 16:30:16 -04:00
end
end