Sha256: 2c7ae70c1f3a38310e4ad40a98aab2f5ab13f3f03de41b2637f8af0fb9c495f5

Contents?: true

Size: 1.96 KB

Versions: 10

Compression:

Stored size: 1.96 KB

Contents

class CarrierMode < ActiveRecord::Base
  self.primary_key = "name"
  
  belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
  belongs_to :mode,    :foreign_key => 'mode_name',    :primary_key => 'name', :class_name => 'ShipmentMode'

  col :name
  col :carrier_name
  col :mode_name
  col :package_volume, :type => :float
  col :route_inefficiency_factor, :type => :float
  col :transport_emission_factor, :type => :float
  col :transport_emission_factor_units
  
  # Don't need to check that carrier_name appears in carriers b/c carriers is derived from carrier_modes.carrier_name
  # Don't need to check that mode_name appears in shipment_modes b/c shipment_modes is derived from carrier_modes.mode_name
  # FIXME TODO test for valid transport_emission_factor_units
  # %w{carrier_name mode_name transport_emission_factor_units}.each do |attribute|
  #   verify "#{attribute.humanize} should never be missing" do
  #     CarrierMode.all.each do |carrier_mode|
  #       value = carrier_mode.send(:"#{attribute}")
  #       unless value.present?
  #         raise "Missing #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}"
  #       end
  #     end
  #   end
  # end
  # 
  # %w{package_volume transport_emission_factor}.each do |attribute|
  #   verify "#{attribute.humanize} should be greater than zero" do
  #     CarrierMode.all.each do |carrier_mode|
  #       value = carrier_mode.send(:"#{attribute}")
  #       unless value > 0
  #         raise "Invalid #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}: #{value} (should be > 0)"
  #       end
  #     end
  #   end
  # end
  # 
  # verify "Route inefficiency factor should be one or more" do
  #   CarrierMode.all.each do |carrier_mode|
  #     unless carrier_mode.route_inefficiency_factor >= 1.0
  #       raise "Invalid route inefficiency factor for CarrierMode #{carrier_mode.name}: #{carrier_mode.route_inefficiency_factor} (should be >= 1.0)"
  #     end
  #   end
  # end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
earth-0.11.20 lib/earth/shipping/carrier_mode.rb
earth-0.11.19 lib/earth/shipping/carrier_mode.rb
earth-0.11.18 lib/earth/shipping/carrier_mode.rb
earth-0.11.17 lib/earth/shipping/carrier_mode.rb
earth-0.11.16 lib/earth/shipping/carrier_mode.rb
earth-0.11.15 lib/earth/shipping/carrier_mode.rb
earth-0.11.14 lib/earth/shipping/carrier_mode.rb
earth-0.11.13 lib/earth/shipping/carrier_mode.rb
earth-0.11.12 lib/earth/shipping/carrier_mode.rb
earth-0.11.11 lib/earth/shipping/carrier_mode.rb