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
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/git_fit/fit/decoder.rb', line 10 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
21 22 23 24 |
# File 'lib/git_fit/fit/decoder.rb', line 21 def self.sport(path) bytes = File.read(path, mode: "rb").bytes CTX.eval("FitDecoder.fitSport(#{bytes.inspect})") end |