Sha256: d74d025998875a83e0a8409a4a29294ad80ed63db4987f4bce2e33636f5f80e8

Contents?: true

Size: 1.39 KB

Versions: 9

Compression:

Stored size: 1.39 KB

Contents

module Logistics
  module Core
    class Route < ApplicationRecord
      belongs_to :from, class_name: 'Logistics::Core::RouteLookup'
      belongs_to :to, class_name: 'Logistics::Core::RouteLookup'
      belongs_to :node, class_name: 'Logistics::Core::RouteLookup'

      has_many :route_rates

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

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

      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/models/logistics/core/route.rb
logistics_core-21.11.1 app/models/logistics/core/route.rb
logistics_core-21.08.1 app/models/logistics/core/route.rb
logistics_core-21.03.1 app/models/logistics/core/route.rb
logistics_core-20.10.3 app/models/logistics/core/route.rb
logistics_core-20.10.2 app/models/logistics/core/route.rb
logistics_core-20.10.1 app/models/logistics/core/route.rb
logistics_core-20.9.1 app/models/logistics/core/route.rb
logistics_core-20.8.1 app/models/logistics/core/route.rb