Class: Mqttopia::Subscriptions::Services::TripPoints
- Defined in:
- lib/mqttopia/subscriptions/services/trip_points.rb
Defined Under Namespace
Classes: TripPointsInvalidError
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#point ⇒ Object
readonly
Returns the value of attribute point.
-
#trip_id ⇒ Object
readonly
Returns the value of attribute trip_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(trip_id:, point:, options: {}) ⇒ TripPoints
constructor
validate :point_json_format.
- #process ⇒ Object
Methods included from Helpers::DataExtractor
#extract_trip_id, #extract_user_id
Constructor Details
#initialize(trip_id:, point:, options: {}) ⇒ TripPoints
validate :point_json_format
19 20 21 22 23 24 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 19 def initialize(trip_id:, point:, options: {}) @trip_id = trip_id @point = point = @user_id = [:user_id] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 13 def end |
#point ⇒ Object (readonly)
Returns the value of attribute point.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 13 def point @point end |
#trip_id ⇒ Object (readonly)
Returns the value of attribute trip_id.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 13 def trip_id @trip_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 13 def user_id @user_id end |
Class Method Details
.call(topic, payload, options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 26 def self.call(topic, payload, = {}) trip_id = topic.include?("trips/") && topic.match(%r{trips/[^/]+}) && extract_trip_id(topic) [:user_id] = topic.include?("user/") && topic.match(%r{user/[^/]+}) && extract_user_id(topic) new(trip_id: trip_id, point: payload, options: ).process end |
Instance Method Details
#process ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/mqttopia/subscriptions/services/trip_points.rb', line 33 def process raise TripPointsInvalidError, errors..to_sentence unless valid? Mqttopia::Serializers::TripPoint.serialize({ trip_id: trip_id, point: point }) end |