Skip to content

Instantly share code, notes, and snippets.

@bill-transue
Created September 8, 2010 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bill-transue/570437 to your computer and use it in GitHub Desktop.
Save bill-transue/570437 to your computer and use it in GitHub Desktop.
class Component < ActiveRecord::Base
belongs_to :cabinet
belongs_to :component_model
has_many :port, :as => :device, :extend => CreatePortFromModel
has_many :sub_components
def elevation
orientation + elevation_index.to_s
end
named_scope :facing, lamba { |orientation| { :conditions => { :orientation => orientation } } } do
def group_by_elevation_index
group_by{|component| component.elevation_index - component.component_model.height + 1 }
end
end
def self.front_facing
self.facing "A"
end
def self.back_facing
self.facing "AB"
end
def self.left_facing
self.facing "AA"
end
def self.right_facing
self.facing "AC"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment