Class: Platform::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/platform/category.rb

Overview

– Copyright © 2010-2012 Michael Berkovich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++

– Platform::Category Schema Information

Table name: platform_categories

id            INTEGER         not null, primary key
type          varchar(255)    
name          varchar(255)    
keyword       varchar(255)    
position      integer         
enable_on     date            
disable_on    date            
parent_id     integer         
created_at    datetime        
updated_at    datetime

Indexes

index_platform_categories_on_parent_id    (parent_id)

++

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.category_id_by_keyword(keyword) ⇒ Object



56
57
58
59
60
# File 'app/models/platform/category.rb', line 56

def self.category_id_by_keyword(keyword)
  cat = find_by_keyword(keyword)
  return nil if not cat
  cat.id
end

.rootObject



52
53
54
# File 'app/models/platform/category.rb', line 52

def self.root
  find_by_keyword('root') || create(:keyword => 'root', :name => 'Root')
end

Instance Method Details



66
67
68
# File 'app/models/platform/category.rb', line 66

def featured_application_categories
  Platform::ApplicationCategory.find(:all, :conditions => ["category_id = ? and featured = ?", self.id, true], :order => "position")
end

#full_nameObject



74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/platform/category.rb', line 74

def full_name
  @full_name ||= begin
    names = [name]
    p = parent 
    while p do
      names << p.name
      p = p.parent
    end
    names.reverse.join(" &raquo; ")
  end
end

#regular_application_categoriesObject



70
71
72
# File 'app/models/platform/category.rb', line 70

def regular_application_categories
  Platform::ApplicationCategory.find(:all, :conditions => ["category_id = ? and (featured is NULL or featured = ?)", self.id, false], :order => "position")
end

#root?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/platform/category.rb', line 62

def root?
  keyword == 'root'  
end