lib/earth/shipping/carrier.rb in earth-0.12.4 vs lib/earth/shipping/carrier.rb in earth-1.0.0
- old
+ new
@@ -1,22 +1,38 @@
+require 'falls_back_on'
+
+require 'earth/model'
+
+require 'earth/shipping/carrier_mode'
+
class Carrier < ActiveRecord::Base
+ extend Earth::Model
+
+ TABLE_STRUCTURE = <<-EOS
+
+CREATE TABLE carriers
+ (
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
+ full_name CHARACTER VARYING(255),
+ package_volume FLOAT,
+ route_inefficiency_factor FLOAT,
+ transport_emission_factor FLOAT,
+ transport_emission_factor_units CHARACTER VARYING(255),
+ corporate_emission_factor FLOAT,
+ corporate_emission_factor_units CHARACTER VARYING(255)
+ );
+
+EOS
+
self.primary_key = "name"
has_many :carrier_modes, :foreign_key => 'carrier_name', :primary_key => 'name'
# TODO calculate these
falls_back_on :route_inefficiency_factor => 1.03,
:transport_emission_factor => 0.0005266,
:corporate_emission_factor => 0.221
- col :name
- col :full_name
- col :package_volume, :type => :float
- col :route_inefficiency_factor, :type => :float
- col :transport_emission_factor, :type => :float
- col :transport_emission_factor_units
- col :corporate_emission_factor, :type => :float
- col :corporate_emission_factor_units
# verify "Package volume should be greater than zero" do
# Carrier.all.each do |carrier|
# unless carrier.package_volume > 0
# raise "Invalid package volume for Carrier #{carrier.name}: #{carrier.package_volume} (should be > 0)"