Module: Rea::AspectType::Classification

Defined in:
lib/rea/aspect_type/classification_aspect.rb

Defined Under Namespace

Modules: Category, CategoryType, ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rea/aspect_type/classification_aspect.rb', line 4

def self.included base
  base.extend ClassMethods
  base.scope :by_category, lambda { |category_type_name, category_name|
    $field_name = base.rea_ast[:classification][category_type_name.to_sym]
    base.where($field_name.to_sym=>category_name)
  }
end

Instance Method Details

#is(category) ⇒ Object



12
13
14
15
# File 'lib/rea/aspect_type/classification_aspect.rb', line 12

def is category
  $field_name = self.class.rea_ast[:classification][category.category_type.name.to_sym]
  self.send($field_name).to_sym == category.name.to_sym
end

#is_in(category) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/rea/aspect_type/classification_aspect.rb', line 17

def is_in category
  field_name = self.class.rea_ast[:classification][category.category_type.name.to_sym]
  $current = category.class.find_by_name(self.send(field_name))
  while($current) do
    return true if $current.name.to_s == category.name.to_s
    $current = $current.parent_category
  end
  return false
end