Class: ProductGroup

Inherits:
ActiveRecord::Base show all
Includes:
Permalink::Builder
Defined in:
app/models/product_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Permalink::Builder

#set_permalink, #to_param

Class Method Details

.contains_product(product) ⇒ Object

list of all product groups containing input product



61
62
63
# File 'app/models/product_group.rb', line 61

def self.contains_product(product)
  all.select { | product_group | product_group.contains?(product) }
end

.fieldsObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/product_group.rb', line 20

def self.fields
  c = []
  c << { "id" => 'name', "name" => 'Name', "field_type" => 'text' }
  c << { "id" => 'price', "name" => 'Price', "field_type" => 'number' }

  CustomField.all.map do | field |
    c << field.attributes.slice("id", "name", "field_type")
  end

  c
end

.operatorsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/product_group.rb', line 32

def self.operators
  {
    text:   [{ name: 'Contains',    value: 'contains' },
             { name: 'Starts With', value: 'starts'},
             { name: 'Ends With',   value:'ends'}],

    number: [{ name: 'Equal', value: 'eq' },
             { name: 'Greater Than', value: 'gt' },
             { name: 'Grater Than Equal To', value:'gteq' },
             { name: 'Less Than', value: 'lt' },
             { name: 'Less Than Equal To', value: 'lteq'}],

    date:   [{ name: 'On', value: 'eq' },
             { name: 'After', value: 'gt' },
             { name: 'On or After', value:'gteq' },
             { name: 'Before', value: 'lt' },
             { name: 'On or Before', value: 'lteq'}],
  }
end

Instance Method Details

#contains?(product) ⇒ Boolean

determines if the given product exists in the product group

Returns:

  • (Boolean)


16
17
18
# File 'app/models/product_group.rb', line 16

def contains?(product)
  products.include?(product)
end

#productsObject



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

def products
  product_group_conditions.search
end

#summarizeObject



56
57
58
# File 'app/models/product_group.rb', line 56

def summarize
  product_group_conditions.map(&:summary).join('  and ')
end