Module: Conjunctions

Included in:
Tweetkit::Search
Defined in:
lib/tweetkit/client/search/conjunctions.rb

Instance Method Summary collapse

Instance Method Details

#append_to_current_query(term) ⇒ Object



407
408
409
410
411
412
413
# File 'lib/tweetkit/client/search/conjunctions.rb', line 407

def append_to_current_query(term)
  if @current_query
    @current_query += " #{term}"
  else
    @current_query = term
  end
end

#are_not_retweets_of(*terms) ⇒ Object



142
143
144
# File 'lib/tweetkit/client/search/conjunctions.rb', line 142

def are_not_retweets_of(*terms)
  join_with_operator(terms, connector: ' ', operator: '-retweets_of')
end

#combine_termsObject



479
480
481
482
483
# File 'lib/tweetkit/client/search/conjunctions.rb', line 479

def combine_terms
  @combined_grouped_terms = @grouped_terms.join(' ')
  @combined_grouped_terms = "(#{@combined_grouped_terms})"
  append_to_current_query(@combined_grouped_terms)
end

#contains(*terms) ⇒ Object



2
3
4
# File 'lib/tweetkit/client/search/conjunctions.rb', line 2

def contains(*terms)
  join(terms, connector: ' ')
end

#contains_one(*terms) ⇒ Object



6
7
8
# File 'lib/tweetkit/client/search/conjunctions.rb', line 6

def contains_one(*terms)
  contains_one_of(*terms)
end

#contains_one_of(*terms) ⇒ Object



10
11
12
# File 'lib/tweetkit/client/search/conjunctions.rb', line 10

def contains_one_of(*terms)
  join(terms, connector: ' OR ')
end

#context(*terms) ⇒ Object



150
151
152
# File 'lib/tweetkit/client/search/conjunctions.rb', line 150

def context(*terms)
  join_with_operator(terms, connector: ' ', operator: 'context')
end

#conversation_id(*terms) ⇒ Object



218
219
220
# File 'lib/tweetkit/client/search/conjunctions.rb', line 218

def conversation_id(*terms)
  conversation_ids(*terms)
end

#conversation_ids(*terms) ⇒ Object



222
223
224
# File 'lib/tweetkit/client/search/conjunctions.rb', line 222

def conversation_ids(*terms)
  join_with_operator(terms, connector: ' ', operator: 'conversation_id')
end

#countries(*terms) ⇒ Object



310
311
312
# File 'lib/tweetkit/client/search/conjunctions.rb', line 310

def countries(*terms)
  from_countries(*terms)
end

#country(*terms) ⇒ Object



306
307
308
# File 'lib/tweetkit/client/search/conjunctions.rb', line 306

def country(*terms)
  from_countries(*terms)
end

#does_not_contain(*terms) ⇒ Object



18
19
20
# File 'lib/tweetkit/client/search/conjunctions.rb', line 18

def does_not_contain(*terms)
  join_with_negated_operator(terms)
end

#does_not_have(*terms) ⇒ Object



38
39
40
# File 'lib/tweetkit/client/search/conjunctions.rb', line 38

def does_not_have(*terms)
  join_with_operator(terms, connector: ' ', operator: '-has')
end

#entities(*terms) ⇒ Object



182
183
184
# File 'lib/tweetkit/client/search/conjunctions.rb', line 182

def entities(*terms)
  join_with_operator(terms, connector: ' ', operator: 'entity')
end

#entity(*terms) ⇒ Object



178
179
180
# File 'lib/tweetkit/client/search/conjunctions.rb', line 178

def entity(*terms)
  entities(*terms)
end

#from(*terms) ⇒ Object



58
59
60
# File 'lib/tweetkit/client/search/conjunctions.rb', line 58

def from(*terms)
  join_with_operator(terms, connector: ' ', operator: 'from')
end

#from_countries(*terms) ⇒ Object



318
319
320
# File 'lib/tweetkit/client/search/conjunctions.rb', line 318

def from_countries(*terms)
  join_with_operator(terms, connector: ' ', operator: 'place_country')
end

#from_country(*terms) ⇒ Object



314
315
316
# File 'lib/tweetkit/client/search/conjunctions.rb', line 314

def from_country(*terms)
  from_countries(*terms)
end

#from_location(*terms) ⇒ Object



258
259
260
# File 'lib/tweetkit/client/search/conjunctions.rb', line 258

def from_location(*terms)
  from_places(*terms)
end

#from_locations(*terms) ⇒ Object



262
263
264
# File 'lib/tweetkit/client/search/conjunctions.rb', line 262

def from_locations(*terms)
  from_places(*terms)
end

#from_one(*terms) ⇒ Object



62
63
64
# File 'lib/tweetkit/client/search/conjunctions.rb', line 62

def from_one(*terms)
  from_one_of(*terms)
end

#from_one_of(*terms) ⇒ Object



66
67
68
# File 'lib/tweetkit/client/search/conjunctions.rb', line 66

def from_one_of(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'from')
end

#from_one_of_countries(*terms) ⇒ Object



326
327
328
# File 'lib/tweetkit/client/search/conjunctions.rb', line 326

def from_one_of_countries(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'place_country')
end

#from_one_of_country(*terms) ⇒ Object



322
323
324
# File 'lib/tweetkit/client/search/conjunctions.rb', line 322

def from_one_of_country(*terms)
  from_one_of_countries(*terms)
end

#from_one_of_location(*terms) ⇒ Object



274
275
276
# File 'lib/tweetkit/client/search/conjunctions.rb', line 274

def from_one_of_location(*terms)
  from_one_of_places(*terms)
end

#from_one_of_locations(*terms) ⇒ Object



278
279
280
# File 'lib/tweetkit/client/search/conjunctions.rb', line 278

def from_one_of_locations(*terms)
  from_one_of_places(*terms)
end

#from_one_of_place(*terms) ⇒ Object



282
283
284
# File 'lib/tweetkit/client/search/conjunctions.rb', line 282

def from_one_of_place(*terms)
  from_one_of_places(*terms)
end

#from_one_of_places(*terms) ⇒ Object



286
287
288
# File 'lib/tweetkit/client/search/conjunctions.rb', line 286

def from_one_of_places(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'place')
end

#from_place(*terms) ⇒ Object



266
267
268
# File 'lib/tweetkit/client/search/conjunctions.rb', line 266

def from_place(*terms)
  from_places(*terms)
end

#from_places(*terms) ⇒ Object



270
271
272
# File 'lib/tweetkit/client/search/conjunctions.rb', line 270

def from_places(*terms)
  join_with_operator(terms, connector: ' ', operator: 'place')
end

#group(&block) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/tweetkit/client/search/conjunctions.rb', line 415

def group(&block)
  Conjunctions.alias_method :original_join, :join
  Conjunctions.alias_method :original_join_with_operator, :join_with_operator
  Conjunctions.alias_method :original_join_with_negated_operator, :join_with_negated_operator

  def join(terms, connector:, **opts)
    unless terms.empty?
      terms = terms.collect do |term|
        term = term.to_s
        term = term.strip
        if term.split.length > 1
          "\"#{term}\""
        else
          term
        end
      end
      terms = terms.join(connector)
      group_terms(terms)
    end
  end

  def join_with_operator(terms, connector:, operator:, **opts)
    unless terms.empty?
      terms = terms.collect do |term|
        term = term.to_s
        term = term.strip
        if term.split.length > 1
          "\"#{term}\""
        else
          term
        end
      end
      terms = terms.collect { |term| "#{operator}:#{term}" }
      terms = terms.join(connector)
      group_terms(terms)
    end
  end

  def join_with_negated_operator(terms, **opts)
    unless terms.empty?
      terms = terms.collect do |term|
        term = term.to_s
        term = term.strip
        if term.split.length > 1
          "\"#{term}\""
        else
          term
        end
      end
      terms = terms.collect { |term| "-#{term}" }
      terms = terms.join(' ')
      group_terms(terms)
    end
  end

  def group_terms(term)
    if @grouped_terms
      @grouped_terms << term
    else
      @grouped_terms = []
      @grouped_terms << term
    end
  end

  def combine_terms
    @combined_grouped_terms = @grouped_terms.join(' ')
    @combined_grouped_terms = "(#{@combined_grouped_terms})"
    append_to_current_query(@combined_grouped_terms)
  end

  instance_eval(&block)
  combine_terms

  Conjunctions.alias_method :join, :original_join
  Conjunctions.alias_method :join_with_operator, :original_join_with_operator
  Conjunctions.alias_method :join_with_negated_operator, :original_join_with_negated_operator

  @combined_grouped_terms
end

#group_terms(term) ⇒ Object



470
471
472
473
474
475
476
477
# File 'lib/tweetkit/client/search/conjunctions.rb', line 470

def group_terms(term)
  if @grouped_terms
    @grouped_terms << term
  else
    @grouped_terms = []
    @grouped_terms << term
  end
end

#has(*terms) ⇒ Object



22
23
24
# File 'lib/tweetkit/client/search/conjunctions.rb', line 22

def has(*terms)
  join_with_operator(terms, connector: ' ', operator: 'has')
end

#has_no(*terms) ⇒ Object



34
35
36
# File 'lib/tweetkit/client/search/conjunctions.rb', line 34

def has_no(*terms)
  does_not_have(*terms)
end

#has_one(*terms) ⇒ Object



26
27
28
# File 'lib/tweetkit/client/search/conjunctions.rb', line 26

def has_one(*terms)
  has_one_of(*terms)
end

#has_one_of(*terms) ⇒ Object



30
31
32
# File 'lib/tweetkit/client/search/conjunctions.rb', line 30

def has_one_of(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'has')
end

#is(*terms) ⇒ Object



46
47
48
# File 'lib/tweetkit/client/search/conjunctions.rb', line 46

def is(*terms)
  join_with_operator(terms, connector: ' ', operator: 'is')
end

#is_a(*terms) ⇒ Object



42
43
44
# File 'lib/tweetkit/client/search/conjunctions.rb', line 42

def is_a(*terms)
  is(*terms)
end

#is_not(*terms) ⇒ Object



54
55
56
# File 'lib/tweetkit/client/search/conjunctions.rb', line 54

def is_not(*terms)
  join_with_operator(terms, connector: ' ', operator: '-is')
end

#is_not_from(*terms) ⇒ Object



74
75
76
# File 'lib/tweetkit/client/search/conjunctions.rb', line 74

def is_not_from(*terms)
  join_with_operator(terms, connector: ' ', operator: '-from')
end

#is_not_to(*terms) ⇒ Object



90
91
92
# File 'lib/tweetkit/client/search/conjunctions.rb', line 90

def is_not_to(*terms)
  join_with_operator(terms, connector: ' ', operator: '-to')
end

#is_one_of(*terms) ⇒ Object



50
51
52
# File 'lib/tweetkit/client/search/conjunctions.rb', line 50

def is_one_of(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'is')
end

#join(terms, connector:, **opts) ⇒ Object



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/tweetkit/client/search/conjunctions.rb', line 354

def join(terms, connector:, **opts)
  unless terms.empty?
    terms = terms.collect do |term|
      term = term.to_s
      term = term.strip
      if term.split.length > 1
        "\"#{term}\""
      else
        term
      end
    end
    terms = terms.join(connector)
    append_to_current_query(terms)
    terms
  end
end

#join_with_negated_operator(terms, **opts) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/tweetkit/client/search/conjunctions.rb', line 389

def join_with_negated_operator(terms, **opts)
  unless terms.empty?
    terms = terms.collect do |term|
      term = term.to_s
      term = term.strip
      if term.split.length > 1
        "\"#{term}\""
      else
        term
      end
    end
    terms = terms.collect { |term| "-#{term}" }
    terms = terms.join(' ')
    append_to_current_query(terms)
    terms
  end
end

#join_with_operator(terms, connector:, operator:, **opts) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/tweetkit/client/search/conjunctions.rb', line 371

def join_with_operator(terms, connector:, operator:, **opts)
  unless terms.empty?
    terms = terms.collect do |term|
      term = term.to_s
      term = term.strip
      if term.split.length > 1
        "\"#{term}\""
      else
        term
      end
    end
    terms = terms.collect { |term| "#{operator}:#{term}" }
    terms = terms.join(connector)
    append_to_current_query(terms)
    terms
  end
end

#lang(*terms) ⇒ Object



338
339
340
# File 'lib/tweetkit/client/search/conjunctions.rb', line 338

def lang(*terms)
  language(*terms)
end

#language(*terms) ⇒ Object



342
343
344
# File 'lib/tweetkit/client/search/conjunctions.rb', line 342

def language(*terms)
  join_with_operator(terms, connector: ' ', operator: 'lang')
end

#location(*terms) ⇒ Object



242
243
244
# File 'lib/tweetkit/client/search/conjunctions.rb', line 242

def location(*terms)
  from_places(*terms)
end

#locations(*terms) ⇒ Object



246
247
248
# File 'lib/tweetkit/client/search/conjunctions.rb', line 246

def locations(*terms)
  from_places(*terms)
end

#not_from(*terms) ⇒ Object



70
71
72
# File 'lib/tweetkit/client/search/conjunctions.rb', line 70

def not_from(*terms)
  is_not_from(*terms)
end

#not_from_countries(*terms) ⇒ Object



334
335
336
# File 'lib/tweetkit/client/search/conjunctions.rb', line 334

def not_from_countries(*terms)
  join_with_operator(terms, connector: ' ', operator: '-place_country')
end

#not_from_country(*terms) ⇒ Object



330
331
332
# File 'lib/tweetkit/client/search/conjunctions.rb', line 330

def not_from_country(*terms)
  not_from_countries(*terms)
end

#not_from_location(*terms) ⇒ Object



290
291
292
# File 'lib/tweetkit/client/search/conjunctions.rb', line 290

def not_from_location(*terms)
  not_from_places(*terms)
end

#not_from_locations(*terms) ⇒ Object



298
299
300
# File 'lib/tweetkit/client/search/conjunctions.rb', line 298

def not_from_locations(*terms)
  not_from_places(*terms)
end

#not_from_place(*terms) ⇒ Object



294
295
296
# File 'lib/tweetkit/client/search/conjunctions.rb', line 294

def not_from_place(*terms)
  not_from_places(*terms)
end

#not_from_places(*terms) ⇒ Object



302
303
304
# File 'lib/tweetkit/client/search/conjunctions.rb', line 302

def not_from_places(*terms)
  join_with_operator(terms, connector: ' ', operator: '-place')
end

#not_lang(*terms) ⇒ Object



346
347
348
# File 'lib/tweetkit/client/search/conjunctions.rb', line 346

def not_lang(*terms)
  not_language(*terms)
end

#not_language(*terms) ⇒ Object



350
351
352
# File 'lib/tweetkit/client/search/conjunctions.rb', line 350

def not_language(*terms)
  join_with_operator(terms, connector: ' ', operator: '-lang')
end

#not_retweets_of(*terms) ⇒ Object



138
139
140
# File 'lib/tweetkit/client/search/conjunctions.rb', line 138

def not_retweets_of(*terms)
  are_not_retweets_of(*terms)
end

#not_to(*terms) ⇒ Object



86
87
88
# File 'lib/tweetkit/client/search/conjunctions.rb', line 86

def not_to(*terms)
  is_not_to(*terms)
end

#not_with_context(*terms) ⇒ Object



166
167
168
# File 'lib/tweetkit/client/search/conjunctions.rb', line 166

def not_with_context(*terms)
  join_with_operator(terms, connector: ' ', operator: '-context')
end

#not_with_entities(*terms) ⇒ Object



206
207
208
# File 'lib/tweetkit/client/search/conjunctions.rb', line 206

def not_with_entities(*terms)
  join_with_operator(terms, connector: ' ', operator: '-entity')
end

#not_with_entity(*terms) ⇒ Object



202
203
204
# File 'lib/tweetkit/client/search/conjunctions.rb', line 202

def not_with_entity(*terms)
  not_with_entities(*terms)
end

#one_of_context(*terms) ⇒ Object



158
159
160
# File 'lib/tweetkit/client/search/conjunctions.rb', line 158

def one_of_context(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'context')
end

#place(*terms) ⇒ Object



250
251
252
# File 'lib/tweetkit/client/search/conjunctions.rb', line 250

def place(*terms)
  from_places(*terms)
end

#places(*terms) ⇒ Object



254
255
256
# File 'lib/tweetkit/client/search/conjunctions.rb', line 254

def places(*terms)
  from_places(*terms)
end

#retweets_of(*terms) ⇒ Object



130
131
132
# File 'lib/tweetkit/client/search/conjunctions.rb', line 130

def retweets_of(*terms)
  join_with_operator(terms, connector: ' ', operator: 'retweets_of')
end

#retweets_of_one_of(*terms) ⇒ Object



134
135
136
# File 'lib/tweetkit/client/search/conjunctions.rb', line 134

def retweets_of_one_of(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'retweets_of')
end

#to(*terms) ⇒ Object



78
79
80
# File 'lib/tweetkit/client/search/conjunctions.rb', line 78

def to(*terms)
  join_with_operator(terms, connector: ' ', operator: 'to')
end

#to_one_of(*terms) ⇒ Object



82
83
84
# File 'lib/tweetkit/client/search/conjunctions.rb', line 82

def to_one_of(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'to')
end

#with_context(*terms) ⇒ Object



146
147
148
# File 'lib/tweetkit/client/search/conjunctions.rb', line 146

def with_context(*terms)
  context(*terms)
end

#with_conversation_id(*terms) ⇒ Object



210
211
212
# File 'lib/tweetkit/client/search/conjunctions.rb', line 210

def with_conversation_id(*terms)
  conversation_ids(*terms)
end

#with_conversation_ids(*terms) ⇒ Object



214
215
216
# File 'lib/tweetkit/client/search/conjunctions.rb', line 214

def with_conversation_ids(*terms)
  conversation_ids(*terms)
end

#with_entities(*terms) ⇒ Object



174
175
176
# File 'lib/tweetkit/client/search/conjunctions.rb', line 174

def with_entities(*terms)
  entities(*terms)
end

#with_entity(*terms) ⇒ Object



170
171
172
# File 'lib/tweetkit/client/search/conjunctions.rb', line 170

def with_entity(*terms)
  entities(*terms)
end


94
95
96
# File 'lib/tweetkit/client/search/conjunctions.rb', line 94

def with_link(term)
  with_url(term)
end


102
103
104
# File 'lib/tweetkit/client/search/conjunctions.rb', line 102

def with_links(*terms)
  with_urls(*terms)
end

#with_one_of_context(*terms) ⇒ Object



154
155
156
# File 'lib/tweetkit/client/search/conjunctions.rb', line 154

def with_one_of_context(*terms)
  one_of_context(*terms)
end

#with_one_of_conversation_id(*terms) ⇒ Object



226
227
228
# File 'lib/tweetkit/client/search/conjunctions.rb', line 226

def with_one_of_conversation_id(*terms)
  with_one_of_conversation_ids(*terms)
end

#with_one_of_conversation_ids(*terms) ⇒ Object



230
231
232
# File 'lib/tweetkit/client/search/conjunctions.rb', line 230

def with_one_of_conversation_ids(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'conversation_id')
end

#with_one_of_entities(*terms) ⇒ Object



190
191
192
# File 'lib/tweetkit/client/search/conjunctions.rb', line 190

def with_one_of_entities(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'entity')
end

#with_one_of_entity(*terms) ⇒ Object



186
187
188
# File 'lib/tweetkit/client/search/conjunctions.rb', line 186

def with_one_of_entity(*terms)
  with_one_of_entities(*terms)
end


110
111
112
# File 'lib/tweetkit/client/search/conjunctions.rb', line 110

def with_one_of_links(*terms)
  with_one_of_urls(*terms)
end

#with_one_of_urls(*terms) ⇒ Object



114
115
116
# File 'lib/tweetkit/client/search/conjunctions.rb', line 114

def with_one_of_urls(*terms)
  join_with_operator(terms, connector: ' OR ', operator: 'url')
end

#with_url(term) ⇒ Object



98
99
100
# File 'lib/tweetkit/client/search/conjunctions.rb', line 98

def with_url(term)
  return "url:#{term}"
end

#with_urls(*terms) ⇒ Object



106
107
108
# File 'lib/tweetkit/client/search/conjunctions.rb', line 106

def with_urls(*terms)
  join_with_operator(terms, connector: ' ', operator: 'url')
end

#without(*terms) ⇒ Object



14
15
16
# File 'lib/tweetkit/client/search/conjunctions.rb', line 14

def without(*terms)
  does_not_contain(*terms)
end

#without_context(*terms) ⇒ Object



162
163
164
# File 'lib/tweetkit/client/search/conjunctions.rb', line 162

def without_context(*terms)
  not_with_context(*terms)
end

#without_conversation_id(*terms) ⇒ Object



234
235
236
# File 'lib/tweetkit/client/search/conjunctions.rb', line 234

def without_conversation_id(*terms)
  without_conversation_ids(*terms)
end

#without_conversation_ids(*terms) ⇒ Object



238
239
240
# File 'lib/tweetkit/client/search/conjunctions.rb', line 238

def without_conversation_ids(*terms)
  join_with_operator(terms, connector: ' ', operator: '-conversation_id')
end

#without_entities(*terms) ⇒ Object



198
199
200
# File 'lib/tweetkit/client/search/conjunctions.rb', line 198

def without_entities(*terms)
  not_with_entities(*terms)
end

#without_entity(*terms) ⇒ Object



194
195
196
# File 'lib/tweetkit/client/search/conjunctions.rb', line 194

def without_entity(*terms)
  not_with_entities(*terms)
end


118
119
120
# File 'lib/tweetkit/client/search/conjunctions.rb', line 118

def without_link(term)
  without_url(term)
end


126
127
128
# File 'lib/tweetkit/client/search/conjunctions.rb', line 126

def without_links(*terms)
  join_with_operator(terms, connector: ' ', operator: '-url')
end

#without_url(term) ⇒ Object



122
123
124
# File 'lib/tweetkit/client/search/conjunctions.rb', line 122

def without_url(term)
  return "-url:#{term}"
end