Class: Druid::FilterDimension

Inherits:
FilterParameter show all
Defined in:
lib/druid/filter.rb

Direct Known Subclasses

CircFilter, FilterJavascript, RecFilter

Instance Method Summary collapse

Methods inherited from FilterParameter

#as_json, #to_json, #to_s

Constructor Details

#initialize(name) ⇒ FilterDimension

Returns a new instance of FilterDimension.



35
36
37
38
39
# File 'lib/druid/filter.rb', line 35

def initialize(name)
  @name = name
  @value = nil
  @regexp = nil
end

Instance Method Details

#!Object



97
98
99
100
101
# File 'lib/druid/filter.rb', line 97

def !()
  filter_not = FilterOperator.new('not', false)
  filter_not.add(self)
  filter_not
end

#&(other) ⇒ Object



83
84
85
86
87
88
# File 'lib/druid/filter.rb', line 83

def &(other)
  filter_and = FilterOperator.new('and', true)
  filter_and.add(self)
  filter_and.add(other)
  filter_and
end

#<(value) ⇒ Object



108
109
110
111
# File 'lib/druid/filter.rb', line 108

def <(value)
  filter_js = FilterJavascript.new_comparison(@name, '<', value)
  filter_js
end

#<=(value) ⇒ Object



118
119
120
121
# File 'lib/druid/filter.rb', line 118

def <=(value)
  filter_js = FilterJavascript.new_comparison(@name, '<=', value)
  filter_js
end

#>(value) ⇒ Object



103
104
105
106
# File 'lib/druid/filter.rb', line 103

def >(value)
  filter_js = FilterJavascript.new_comparison(@name, '>', value)
  filter_js
end

#>=(value) ⇒ Object



113
114
115
116
# File 'lib/druid/filter.rb', line 113

def >=(value)
  filter_js = FilterJavascript.new_comparison(@name, '>=', value)
  filter_js
end

#eq(value) ⇒ Object Also known as: ==



49
50
51
52
53
54
# File 'lib/druid/filter.rb', line 49

def eq(value)
  return self.in(value) if value.is_a? Array
  return self.regexp(value) if value.is_a? Regexp
  @value = value
  self
end

#in(*args) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/druid/filter.rb', line 65

def in(*args)
  values = args.flatten
  raise "Must provide non-empty array in in()" if values.empty?

  if (values.length == 1)
    return self.eq(values[0])
  end

  filter_or = FilterOperator.new('or', true)
  values.each do |value|
    raise "query is too complex" if value.is_a? FilterParameter
    param = FilterDimension.new(@name)
    param.eq value
    filter_or.add param
  end
  filter_or
end

#in_circ(bounds) ⇒ Object



45
46
47
# File 'lib/druid/filter.rb', line 45

def in_circ(bounds)
  CircFilter.new(@name, bounds)
end

#in_rec(bounds) ⇒ Object



41
42
43
# File 'lib/druid/filter.rb', line 41

def in_rec(bounds)
  RecFilter.new(@name, bounds)
end

#javascript(js) ⇒ Object



123
124
125
126
# File 'lib/druid/filter.rb', line 123

def javascript(js)
  filter_js = FilterJavascript.new(@name, js)
  filter_js
end

#neq(value) ⇒ Object Also known as: !=



59
60
61
# File 'lib/druid/filter.rb', line 59

def neq(value)
  return !self.in(value)
end

#regexp(r) ⇒ Object



128
129
130
131
132
# File 'lib/druid/filter.rb', line 128

def regexp(r)
  r = Regexp.new(r) unless r.is_a? Regexp
  @regexp = r.inspect[1...-1] #to_s doesn't work
  self
end

#to_hashObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/druid/filter.rb', line 134

def to_hash
  raise 'no value assigned' unless @value.nil? ^ @regexp.nil?
  hash = {
    :dimension => @name
  }
  if @value
    hash['type'] = 'selector'
    hash['value'] = @value
  elsif @regexp
    hash['type'] = 'regex'
    hash['pattern'] = @regexp
  end
  hash
end

#|(other) ⇒ Object



90
91
92
93
94
95
# File 'lib/druid/filter.rb', line 90

def |(other)
  filter_or = FilterOperator.new('or', true)
  filter_or.add(self)
  filter_or.add(other)
  filter_or
end