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



88
89
90
91
92
# File 'lib/druid/filter.rb', line 88

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

#&(other) ⇒ Object



74
75
76
77
78
79
# File 'lib/druid/filter.rb', line 74

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

#<(value) ⇒ Object



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

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

#<=(value) ⇒ Object



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

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

#>(value) ⇒ Object



94
95
96
97
# File 'lib/druid/filter.rb', line 94

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

#>=(value) ⇒ Object



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

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



64
65
66
67
# File 'lib/druid/filter.rb', line 64

def in(*args)
  values = args.flatten
  filter_multiple(values, 'or', :eq)
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



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

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

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



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

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

#nin(*args) ⇒ Object



69
70
71
72
# File 'lib/druid/filter.rb', line 69

def nin(*args)
  values = args.flatten
  filter_multiple(values, 'and', :neq)
end

#regexp(r) ⇒ Object



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

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



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/druid/filter.rb', line 125

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



81
82
83
84
85
86
# File 'lib/druid/filter.rb', line 81

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