Class: Supernova::Condition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, type) ⇒ Condition

Returns a new instance of Condition.



4
5
6
7
# File 'lib/supernova/condition.rb', line 4

def initialize(key, type)
  self.key = key
  self.type = type
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



2
3
4
# File 'lib/supernova/condition.rb', line 2

def key
  @key
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/supernova/condition.rb', line 2

def type
  @type
end

Instance Method Details

#solr_filter_for(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/supernova/condition.rb', line 9

def solr_filter_for(value)
  case type
    when :not, :ne
      if value.nil?
        "#{self.key}:[* TO *]"
      else
        "!#{self.key}:#{value}"
      end
    when :gt
      "#{self.key}:{#{value} TO *}"
    when :gte
      "#{self.key}:[#{value} TO *]"
    when :lt
      "#{self.key}:{* TO #{value}}"
    when :lte
      "#{self.key}:[* TO #{value}]"
  end
end