Class: ProductFeatureType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProductFeatureType
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/product_feature_type.rb
Overview
create_table :product_feature_types do |t|
t.integer :parent_id
t.integer :lft
t.integer :rgt
t.string :description
t.string :internal_identifier
t.string :external_identifier
t.string :external_id
t.
end
add_index :product_feature_types, :internal_identifier, name: ‘product_ft_types_iid_idx’ add_index :product_feature_types, [:rgt, :lft, :parent_id], name: ‘product_ft_types_nested_set_idx’
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.iid(description) ⇒ Object
31 32 33 |
# File 'app/models/product_feature_type.rb', line 31 def self.iid(description) self.where("lower(description) = ?", description.downcase).first end |
.to_all_representation(root = ProductFeatureType.root) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/models/product_feature_type.rb', line 53 def self.to_all_representation(root = ProductFeatureType.root) # returns an array of hashes which represent all categories in nested set order, # each of which consists of the category's id and representation container_arr = [] each_with_level(root.self_and_descendants) do |o, level| container_arr << {:id => o.id, :description => o.to_representation} end container_arr end |
Instance Method Details
#to_record_representation(root = ProductFeatureType.root) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/models/product_feature_type.rb', line 35 def to_record_representation(root = ProductFeatureType.root) # returns a string of category descriptions like # 'main_category > sub_category n > ... > this category instance' if root? description else crawl_up_from(self, root).split('///').reverse.join(' > ') end end |
#to_representation ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/product_feature_type.rb', line 45 def to_representation # returns a string that consists of 1) a number of dashes equal to # the category's level and 2) the category's description attr rep = '' level.times {rep << '- '} rep << description end |