Class: Logistics::Core::Route

Inherits:
ApplicationRecord show all
Defined in:
app/models/logistics/core/route.rb

Direct Known Subclasses

InterCityRoute, WithinCityRoute

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

as_json

Class Method Details

.fetch_allObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/logistics/core/route.rb', line 23

def self.fetch_all
  result = []
  Route.all.order('route_type').each do |route|
    result.push({id: route.id,
                 from_id: route.from_id,
                 from: route.from ? route.from.name : nil,
                 to_id: route.to_id,
                 to: route.to ? route.to.name : nil,
                 route_name: route.route_name,
                 node_id: route.node_id,
                 node_name: route.node ? route.node.name : nil,
                 zone: route.zone,
                 radius: route.radius,
                 route_type: route.route_type,
                 description: route.description,
                 margin: route.margin
                })
  end
  return result
end

.route_typeObject



10
11
12
# File 'app/models/logistics/core/route.rb', line 10

def self.route_type
  %w(InterCityRoute, WithinCityRoute)
end

Instance Method Details

#route_nameObject



14
15
16
17
18
19
20
21
# File 'app/models/logistics/core/route.rb', line 14

def route_name
  if from && to
    from.name + ' - ' + to.name
  else
    node_name = node ? node.name : nil
    node_name + ' - ' + self.zone
  end
end