lib/algolia/models/recommend/condition.rb in algolia-3.0.0.alpha.12 vs lib/algolia/models/recommend/condition.rb in algolia-3.0.0.alpha.13
- old
+ new
@@ -4,21 +4,24 @@
require 'time'
module Algolia
module Recommend
class Condition
- # Query pattern syntax.
+ # Query pattern that triggers the rule. You can use either a literal string, or a special pattern `{facet:ATTRIBUTE}`, where `ATTRIBUTE` is a facet name. The rule is triggered if the query matches the literal string or a value of the specified facet. For example, with `pattern: {facet:genre}`, the rule is triggered when users search for a genre, such as \"comedy\".
attr_accessor :pattern
attr_accessor :anchoring
- # Whether the pattern matches on plurals, synonyms, and typos.
+ # Whether the pattern should match plurals, synonyms, and typos.
attr_accessor :alternatives
- # Rule context format: [A-Za-z0-9_-]+).
+ # An additional restriction that only triggers the rule, when the search has the same value as `ruleContexts` parameter. For example, if `context: mobile`, the rule is only triggered when the search request has a matching `ruleContexts: mobile`. A rule context must only contain alphanumeric characters.
attr_accessor :context
+ # Filters that trigger the rule. You can add add filters using the syntax `facet:value` so that the rule is triggered, when the specific filter is selected. You can use `filters` on its own or combine it with the `pattern` parameter.
+ attr_accessor :filters
+
class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values
def initialize(datatype, allowable_values)
@@ -43,11 +46,12 @@
def self.attribute_map
{
:pattern => :pattern,
:anchoring => :anchoring,
:alternatives => :alternatives,
- :context => :context
+ :context => :context,
+ :filters => :filters
}
end
# Returns all the JSON keys this model knows about
def self.acceptable_attributes
@@ -58,11 +62,12 @@
def self.types_mapping
{
:pattern => :String,
:anchoring => :Anchoring,
:alternatives => :Boolean,
- :context => :String
+ :context => :String,
+ :filters => :String
}
end
# List of attributes with nullable: true
def self.openapi_nullable
@@ -99,22 +104,42 @@
end
if attributes.key?(:context)
self.context = attributes[:context]
end
+
+ if attributes.key?(:filters)
+ self.filters = attributes[:filters]
+ end
end
+ # Custom attribute writer method with validation
+ # @param [Object] context Value to be assigned
+ def context=(context)
+ if context.nil?
+ raise ArgumentError, 'context cannot be nil'
+ end
+
+ pattern = /[A-Za-z0-9_-]+/
+ if context !~ pattern
+ raise ArgumentError, "invalid value for \"context\", must conform to the pattern #{pattern}."
+ end
+
+ @context = context
+ end
+
# Checks equality by comparing each attribute.
# @param [Object] Object to be compared
def ==(other)
return true if equal?(other)
self.class == other.class &&
pattern == other.pattern &&
anchoring == other.anchoring &&
alternatives == other.alternatives &&
- context == other.context
+ context == other.context &&
+ filters == other.filters
end
# @see the `==` method
# @param [Object] Object to be compared
def eql?(other)
@@ -122,10 +147,10 @@
end
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
- [pattern, anchoring, alternatives, context].hash
+ [pattern, anchoring, alternatives, context, filters].hash
end
# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself