Class: GitFit::FIT::Decoder
- Inherits:
-
Object
- Object
- GitFit::FIT::Decoder
- Defined in:
- lib/git_fit/fit/decoder.rb
Constant Summary collapse
- JS_CODE =
File.read(File.join(__dir__, 'decoder.js')).freeze
- CTX =
MiniRacer::Context.new.tap { |c| c.eval(JS_CODE) }
Class Method Summary collapse
Class Method Details
.decode(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/git_fit/fit/decoder.rb', line 12 def self.decode(path) bytes = File.read(path, mode: 'rb').bytes json = CTX.eval("FitDecoder.decodeFit(#{bytes.inspect})") records = JSON.parse(json) records.each do |r| r['positionLat'] *= 180 if r['positionLat'] r['positionLong'] *= 180 if r['positionLong'] end records end |
.sport(path) ⇒ Object
23 24 25 26 |
# File 'lib/git_fit/fit/decoder.rb', line 23 def self.sport(path) bytes = File.read(path, mode: 'rb').bytes CTX.eval("FitDecoder.fitSport(#{bytes.inspect})") end |