Class: Magentwo::Filter::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/filter.rb

Direct Known Subclasses

CompareArray, Eq, From, Gt, Gteq, Like, Lt, Lteq, Neq, To

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ Compare

Returns a new instance of Compare.



5
6
7
8
# File 'lib/filter.rb', line 5

def initialize field, value
  @field = field
  @value = value
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



4
5
6
# File 'lib/filter.rb', line 4

def field
  @field
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/filter.rb', line 4

def value
  @value
end

Instance Method Details

#to_query(idx, field: self.field, value: self.value) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/filter.rb', line 10

def to_query idx, field:self.field, value:self.value
  [
  "searchCriteria[filter_groups][#{idx}][filters][0][field]=#{self.field}",
  "searchCriteria[filter_groups][#{idx}][filters][0][value]=#{CGI.escape(self.value.to_s)}",
  "searchCriteria[filter_groups][#{idx}][filters][0][condition_type]=#{self.class.name.split("::").last.downcase}"]
  .join("&")
end

#to_sObject



18
19
20
# File 'lib/filter.rb', line 18

def to_s
  "#{self.field} #{self.class.name.split("::").last.downcase} #{self.value}"
end