Class: Groonga::ExpressionBuildable::ColumnValueExpressionBuilder

Inherits:
ExpressionBuilder
  • Object
show all
Defined in:
lib/groonga/expression-builder.rb

Direct Known Subclasses

MatchTargetColumnExpressionBuilder

Instance Method Summary collapse

Methods inherited from ExpressionBuilder

#&, #|

Constructor Details

#initialize(column, options = {}) ⇒ ColumnValueExpressionBuilder

Returns a new instance of ColumnValueExpressionBuilder.



154
155
156
157
158
159
160
161
# File 'lib/groonga/expression-builder.rb', line 154

def initialize(column, options={})
  super()
  @table = options[:table] || column.table
  @column = column
  @column_name = options[:column_name] || @column.local_name
  @range = options[:range] || @column.range
  @name = options[:name]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/groonga/expression-builder.rb', line 282

def method_missing(name, *args, &block)
  return super if block

  if args.empty? and VALID_COLUMN_NAME_RE =~ name.to_s
    accessor_name = "#{@column_name}.#{name}"
    accessor = @table.column(accessor_name)
    if accessor
      return self.class.new(accessor,
                            :table => @table,
                            :column_name => accessor_name)
    end
  end

  object = @table.context[name]
  if callable_object?(object)
    return CallExpressionBuilder.new(object, self, *args)
  end

  super
end

Instance Method Details

#!=(other) ⇒ Object



177
178
179
# File 'lib/groonga/expression-builder.rb', line 177

def !=(other)
  NotEqualExpressionBuilder.new(self, normalize(other))
end

#%(other) ⇒ Object



227
228
229
# File 'lib/groonga/expression-builder.rb', line 227

def %(other)
  ModExpressionBuilder.new(self, normalize(other))
end

#*(other) ⇒ Object



219
220
221
# File 'lib/groonga/expression-builder.rb', line 219

def *(other)
  StarExpressionBuilder.new(self, normalize(other))
end

#+(other) ⇒ Object



211
212
213
# File 'lib/groonga/expression-builder.rb', line 211

def +(other)
  PlusExpressionBuilder.new(self, normalize(other))
end

#-(other) ⇒ Object



215
216
217
# File 'lib/groonga/expression-builder.rb', line 215

def -(other)
  MinusExpressionBuilder.new(self, normalize(other))
end

#/(other) ⇒ Object



223
224
225
# File 'lib/groonga/expression-builder.rb', line 223

def /(other)
  SlashExpressionBuilder.new(self, normalize(other))
end

#<(other) ⇒ Object



195
196
197
# File 'lib/groonga/expression-builder.rb', line 195

def <(other)
  LessExpressionBuilder.new(self, normalize(other))
end

#<=(other) ⇒ Object



199
200
201
# File 'lib/groonga/expression-builder.rb', line 199

def <=(other)
  LessEqualExpressionBuilder.new(self, normalize(other))
end

#==(other) ⇒ Object



173
174
175
# File 'lib/groonga/expression-builder.rb', line 173

def ==(other)
  EqualExpressionBuilder.new(self, normalize(other))
end

#=~(other) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/groonga/expression-builder.rb', line 181

def =~(other)
  if other.nil?
    full_column_name = "#{@table.name}.#{@column_name}"
    raise ArgumentError,
           "match word should not be nil: #{full_column_name}"
  end

  if other.is_a?(Regexp)
    RegexpExpressionBuilder.new(self, normalize(other.source))
  else
    MatchExpressionBuilder.new(self, normalize(other))
  end
end

#>(other) ⇒ Object



203
204
205
# File 'lib/groonga/expression-builder.rb', line 203

def >(other)
  GreaterExpressionBuilder.new(self, normalize(other))
end

#>=(other) ⇒ Object



207
208
209
# File 'lib/groonga/expression-builder.rb', line 207

def >=(other)
  GreaterEqualExpressionBuilder.new(self, normalize(other))
end

#build(expression, variable) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/groonga/expression-builder.rb', line 163

def build(expression, variable)
  expression.append_object(variable)
  if @column.is_a?(String)
    expression.append_constant(@column)
  else
    expression.append_object(@column)
  end
  expression.append_operation(Groonga::Operation::GET_VALUE, 2)
end

#match(query, options = {}) ⇒ Object



231
232
233
234
235
236
# File 'lib/groonga/expression-builder.rb', line 231

def match(query, options={})
  options = options.dup
  options[:syntax] ||= :query
  options[:default_column] = @column_name
  SubExpressionBuilder.new(query, options)
end

#prefix_search(other) ⇒ Object



238
239
240
# File 'lib/groonga/expression-builder.rb', line 238

def prefix_search(other)
  PrefixSearchExpressionBuilder.new(self, normalize(other))
end

#similar_search(other) ⇒ Object



246
247
248
# File 'lib/groonga/expression-builder.rb', line 246

def similar_search(other)
  SimilarSearchExpressionBuilder.new(self, normalize(other))
end

#suffix_search(other) ⇒ Object



242
243
244
# File 'lib/groonga/expression-builder.rb', line 242

def suffix_search(other)
  SuffixSearchExpressionBuilder.new(self, normalize(other))
end

#term_extract(other) ⇒ Object



250
251
252
253
254
255
256
257
258
# File 'lib/groonga/expression-builder.rb', line 250

def term_extract(other)
  if @column_name == "_key"
    TermExtractExpressionBuilder.new(self, normalize(other))
  else
    message = "term extraction supports _key column only: " +
      "<#{@column_name}>"
    raise ArgumentError, message
  end
end