Class: Workarea::ProductRule

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/product_rule.rb

Constant Summary collapse

OPERATORS =
%w(
  greater_than
  greater_than_or_equal
  equals
  not_equal
  less_than
  less_than_or_equal
)

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Instance Method Details

#category?Boolean

Determines if the rule is a for a category.

Returns:

  • (Boolean)


108
109
110
# File 'app/models/workarea/product_rule.rb', line 108

def category?
  slug == :category
end

#comparison?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
# File 'app/models/workarea/product_rule.rb', line 95

def comparison?
  operator.in?([
    'greater_than',
    'greater_than_or_equal',
    'less_than',
    'less_than_or_equal'
  ])
end

#created_at?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/workarea/product_rule.rb', line 75

def created_at?
  slug == :created_at
end

#equality?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/workarea/product_rule.rb', line 79

def equality?
  operator == 'equals'
end

#false?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/workarea/product_rule.rb', line 91

def false?
  value.downcase == 'false'
end

#fieldString

The field in Elasticsearch this rule checks against

Returns:



37
38
39
40
# File 'app/models/workarea/product_rule.rb', line 37

def field
  return if name.blank?
  Workarea.config.product_rule_fields[slug] || "facets.#{name.systemize}"
end

#inequality?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/workarea/product_rule.rb', line 83

def inequality?
  operator == 'not_equal'
end

#inventory?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/workarea/product_rule.rb', line 71

def inventory?
  slug == :inventory
end

#product_exclusion?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'app/models/workarea/product_rule.rb', line 112

def product_exclusion?
  slug == :excluded_products
end

#sale?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/workarea/product_rule.rb', line 63

def sale?
  slug == :on_sale
end

#search?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/workarea/product_rule.rb', line 67

def search?
  slug == :search
end

#slugSymbol

The identifier for which admin partials to render for this rule.

Returns:

  • (Symbol)


29
30
31
# File 'app/models/workarea/product_rule.rb', line 29

def slug
  name.systemize.to_sym if name.present?
end

#termsArray<String>

Used in query-building for Elasticsearch

Returns:



120
121
122
# File 'app/models/workarea/product_rule.rb', line 120

def terms
  value.to_s.split(',').map(&:strip).reject(&:blank?)
end

#true?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/workarea/product_rule.rb', line 87

def true?
  value.downcase == 'true'
end

#valueComparable

Returns the value that the rule uses to compare.

Returns:

  • (Comparable)


48
49
50
51
# File 'app/models/workarea/product_rule.rb', line 48

def value
  return Time.zone.parse(value_field) rescue value_field if created_at?
  value_field
end

#value=(val) ⇒ Object

This is HACK for the fact that we want a CSV string in value, but our current solution for submitting category IDs submits an array. :(



55
56
57
58
59
60
61
# File 'app/models/workarea/product_rule.rb', line 55

def value=(val)
  if val.is_a?(Array)
    super(val.join(','))
  else
    super(val)
  end
end

#value_fieldObject



42
# File 'app/models/workarea/product_rule.rb', line 42

alias_method :value_field, :value