Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Forked from bill-transue/gist:570437
Created September 8, 2010 17:20
Show Gist options
  • Save jackdempsey/570444 to your computer and use it in GitHub Desktop.
Save jackdempsey/570444 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; facing "A"; end
def self.back_facing; facing "AB"; end
def self.left_facing; facing "AA"; end
def self.right_facing; facing "AC"; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment