Class: TravelTime::ProtoUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/utils.rb

Overview

Utilities for encoding/decoding protobuf requests

Class Method Summary collapse

Class Method Details

.build_deltas(departure, destinations) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/utils.rb', line 14

def self.build_deltas(departure, destinations)
  deltas = destinations.map do |destination|
    [encode_fixed_point(departure[:lat], destination[:lat]),
     encode_fixed_point(departure[:lng], destination[:lng])]
  end
  deltas.flatten
end

.decode_proto_response(response) ⇒ Object



45
46
47
# File 'lib/utils.rb', line 45

def self.decode_proto_response(response)
  Com::Igeolise::Traveltime::Rabbitmq::Responses::TimeFilterFastResponse.decode(response).to_h
end

.encode_fixed_point(source, target) ⇒ Object



10
11
12
# File 'lib/utils.rb', line 10

def self.encode_fixed_point(source, target)
  ((target - source) * 10.pow(5)).round
end

.encode_proto_message(message) ⇒ Object



41
42
43
# File 'lib/utils.rb', line 41

def self.encode_proto_message(message)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.encode(message)
end

.make_one_to_many(origin, destinations, transport_obj, traveltime, properties) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/utils.rb', line 22

def self.make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
  transportation = Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new
  transport_obj.apply_to_proto(transportation)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::OneToMany.new(
    departureLocation: origin,
    locationDeltas: build_deltas(origin, destinations),
    transportation: transportation,
    arrivalTimePeriod: 0,
    travelTime: traveltime,
    properties: properties
  )
end

.make_proto_message(origin, destinations, transport_obj, traveltime, properties: nil) ⇒ Object



35
36
37
38
39
# File 'lib/utils.rb', line 35

def self.make_proto_message(origin, destinations, transport_obj, traveltime, properties: nil)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new(
    oneToManyRequest: make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
  )
end