Module: Oedipus::Comparison::Shortcuts

Extended by:
Shortcuts
Included in:
Oedipus, Shortcuts
Defined in:
lib/oedipus/comparison/shortcuts.rb

Overview

Provides short methods for casting values to Comparisons.

Instance Method Summary collapse

Instance Method Details

#between(a, b = nil) ⇒ Comparison::Between

Return the Comparison for the range a..b.

Parameters:

  • v (Object)

    either a Range, or a number

  • b (Fixnum) (defaults to: nil)

    if the first argument was a number, the other bound

Returns:



59
60
61
# File 'lib/oedipus/comparison/shortcuts.rb', line 59

def between(a, b = nil)
  Between.new(a.kind_of?(Range) ? a : a..b)
end

#eq(v) ⇒ Comparison::Equal

Return the Comparison for equality of v.

Parameters:

  • v (Object)

    any ruby object to compare in a query

Returns:



23
24
25
# File 'lib/oedipus/comparison/shortcuts.rb', line 23

def eq(v)
  Equal.new(v)
end

#gt(v) ⇒ Comparison::GT

Return the Comparison for > v.

Parameters:

  • v (Object)

    a number to compare

Returns:



117
118
119
# File 'lib/oedipus/comparison/shortcuts.rb', line 117

def gt(v)
  GT.new(v)
end

#gte(v) ⇒ Comparison::GTE

Return the Comparison for >= v.

Parameters:

  • v (Object)

    a number to compare

Returns:



106
107
108
# File 'lib/oedipus/comparison/shortcuts.rb', line 106

def gte(v)
  GTE.new(v)
end

#in(*v) ⇒ Comparison::In

Return the Comparison for any value in the set v.

Parameters:

  • v (Object)

    any ruby object to compare

Returns:



84
85
86
# File 'lib/oedipus/comparison/shortcuts.rb', line 84

def in(*v)
  In.new(v.map { |el| el.respond_to?(:to_a) ? el.to_a : el }.flatten)
end

#lt(v) ⇒ Comparison::LT

Return the Comparison for < v.

Parameters:

  • v (Object)

    a number to compare

Returns:



139
140
141
# File 'lib/oedipus/comparison/shortcuts.rb', line 139

def lt(v)
  LT.new(v)
end

#lte(v) ⇒ Comparison::LTE

Return the Comparison for <= v.

Parameters:

  • v (Object)

    a number to compare

Returns:



128
129
130
# File 'lib/oedipus/comparison/shortcuts.rb', line 128

def lte(v)
  LTE.new(v)
end

#neq(v) ⇒ Comparison::Equal

Return the Comparison for inequality of v.

Parameters:

  • v (Object)

    any ruby object to compare in a query

Returns:



34
35
36
# File 'lib/oedipus/comparison/shortcuts.rb', line 34

def neq(v)
  NotEqual.new(v)
end

#not(v) ⇒ Comparison::Not

Return the Comparison for negation of v.

Parameters:

  • v (Object)

    any ruby object to compare in a query

Returns:



45
46
47
# File 'lib/oedipus/comparison/shortcuts.rb', line 45

def not(v)
  Not.new(v)
end

#not_in(*v) ⇒ Comparison::NotIn

Return the Comparison for any value NOT in the set v.

Parameters:

  • v (Object)

    any ruby object to compare

Returns:



95
96
97
# File 'lib/oedipus/comparison/shortcuts.rb', line 95

def not_in(*v)
  NotIn.new(v.map { |el| el.respond_to?(:to_a) ? el.to_a : el }.flatten)
end

#outside(a, b = nil) ⇒ Comparison::Outside

Return the Comparison to exclude the range a..b.

Parameters:

  • v (Object)

    either a Range, or a number

  • b (Fixnum) (defaults to: nil)

    if the first argument was a number, the other bound

Returns:



73
74
75
# File 'lib/oedipus/comparison/shortcuts.rb', line 73

def outside(a, b = nil)
  Outside.new(a.kind_of?(Range) ? a : a..b)
end