Class: GitFit::Parser::Tbulu

Inherits:
Base
  • Object
show all
Defined in:
lib/git_fit/parser/tbulu.rb

Constant Summary collapse

MAGIC =
'##tk'.b
MOD32 =
2**32
HOUR8 =
8 * 3600 * 1000
SPORT_TYPE_MAP =
{
  3 => 'hike',
  18 => 'hike',
  24 => 'run',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GitFit::Parser::Base

Class Method Details

.sniff_format(content) ⇒ Object



19
20
21
22
23
24
# File 'lib/git_fit/parser/tbulu.rb', line 19

def self.sniff_format(content)
  return :tk if content.start_with?(MAGIC)
  return :kml if content.lstrip.start_with?('<kml', '<?xml')

  nil
end

Instance Method Details

#call(input) ⇒ Object



26
27
28
29
# File 'lib/git_fit/parser/tbulu.rb', line 26

def call(input)
  activities, = call_with_points(input)
  activities
end

#call_with_points(input) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/git_fit/parser/tbulu.rb', line 31

def call_with_points(input)
  content = input.is_a?(String) ? input.b : input
  return [[], []] if content.nil? || content.empty?

  format = sniff_format(content)
  case format
  when :tk then parse_2tk_full(content)
  when :kml then parse_kml_full(content)
  else
    [[], []]
  end
end

#extract_points(input) ⇒ Object



44
45
46
47
# File 'lib/git_fit/parser/tbulu.rb', line 44

def extract_points(input)
  _, points = call_with_points(input)
  points
end