class Sequel::SQL::CaseExpression

  1. lib/sequel/sql.rb
Parent: SQL

Represents an SQL CASE expression, used for conditional branching in SQL.

Methods

Public Class

  1. new

Public Instance

  1. conditions
  2. default
  3. expression
  4. expression?

Attributes

conditions [R]

An array of all two pairs with the first element specifying the condition and the second element specifying the result if the condition matches.

default [R]

The default value if no conditions match.

expression [R]

The expression to test the conditions against

Public Class methods

new (conditions, default, expression=(no_expression=true; nil))

Create an object with the given conditions and default value. An expression can be provided to test each condition against, instead of having all conditions represent their own boolean expression.

[show source]
# File lib/sequel/sql.rb, line 967
def initialize(conditions, default, expression=(no_expression=true; nil))
  raise(Sequel::Error, 'CaseExpression conditions must be a hash or array of all two pairs') unless Sequel.condition_specifier?(conditions)
  @conditions, @default, @expression, @no_expression = conditions.to_a, default, expression, no_expression
end

Public Instance methods

expression? ()

Whether to use an expression for this CASE expression.

[show source]
# File lib/sequel/sql.rb, line 973
def expression?
  !@no_expression
end