Class: Druid::FilterDimension
Instance Method Summary
collapse
#as_json, #to_json, #to_s
Constructor Details
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
89
90
91
92
93
|
# File 'lib/druid/filter.rb', line 89
def !()
filter_not = FilterOperator.new('not', false)
filter_not.add(self)
filter_not
end
|
#&(other) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/druid/filter.rb', line 75
def &(other)
filter_and = FilterOperator.new('and', true)
filter_and.add(self)
filter_and.add(other)
filter_and
end
|
#<(value) ⇒ Object
100
101
102
103
|
# File 'lib/druid/filter.rb', line 100
def <(value)
filter_js = FilterJavascript.new_comparison(@name, '<', value)
filter_js
end
|
#<=(value) ⇒ Object
110
111
112
113
|
# File 'lib/druid/filter.rb', line 110
def <=(value)
filter_js = FilterJavascript.new_comparison(@name, '<=', value)
filter_js
end
|
#>(value) ⇒ Object
95
96
97
98
|
# File 'lib/druid/filter.rb', line 95
def >(value)
filter_js = FilterJavascript.new_comparison(@name, '>', value)
filter_js
end
|
#>=(value) ⇒ Object
105
106
107
108
|
# File 'lib/druid/filter.rb', line 105
def >=(value)
filter_js = FilterJavascript.new_comparison(@name, '>=', value)
filter_js
end
|
#eq(value) ⇒ Object
Also known as:
==
41
42
43
44
45
46
|
# File 'lib/druid/filter.rb', line 41
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/druid/filter.rb', line 57
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
|
#javascript(js) ⇒ Object
115
116
117
118
|
# File 'lib/druid/filter.rb', line 115
def javascript(js)
filter_js = FilterJavascript.new(@name, js)
filter_js
end
|
#neq(value) ⇒ Object
Also known as:
!=
51
52
53
|
# File 'lib/druid/filter.rb', line 51
def neq(value)
return !self.in(value)
end
|
#regexp(r) ⇒ Object
120
121
122
123
124
|
# File 'lib/druid/filter.rb', line 120
def regexp(r)
r = Regexp.new(r) unless r.is_a? Regexp
@regexp = r.inspect[1...-1]
self
end
|
#to_hash ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/druid/filter.rb', line 126
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
82
83
84
85
86
87
|
# File 'lib/druid/filter.rb', line 82
def |(other)
filter_or = FilterOperator.new('or', true)
filter_or.add(self)
filter_or.add(other)
filter_or
end
|