Class: ProductGroup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProductGroup
- Includes:
- Permalink::Builder
- Defined in:
- app/models/product_group.rb
Class Method Summary collapse
-
.contains_product(product) ⇒ Object
list of all product groups containing input product.
- .fields ⇒ Object
- .operators ⇒ Object
Instance Method Summary collapse
-
#contains?(product) ⇒ Boolean
determines if the given product exists in the product group.
- #products ⇒ Object
- #summarize ⇒ Object
Methods included from Permalink::Builder
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 |
.fields ⇒ Object
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 |
.operators ⇒ Object
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
16 17 18 |
# File 'app/models/product_group.rb', line 16 def contains?(product) products.include?(product) end |
#products ⇒ Object
52 53 54 |
# File 'app/models/product_group.rb', line 52 def products product_group_conditions.search end |
#summarize ⇒ Object
56 57 58 |
# File 'app/models/product_group.rb', line 56 def summarize product_group_conditions.map(&:summary).join(' and ') end |