Class: Sequel::SQL::CaseExpression
- Inherits:
-
GenericExpression
- Object
- Expression
- GenericExpression
- Sequel::SQL::CaseExpression
- Defined in:
- lib/sequel/lib/sequel/sql.rb
Overview
Represents an SQL CASE expression, used for conditions.
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
An array of all two pairs with the first element specifying the condition and the second element specifying the result.
-
#default ⇒ Object
readonly
The default value if no conditions are true.
-
#expression ⇒ Object
readonly
The expression to test the conditions against.
Instance Method Summary collapse
-
#initialize(conditions, default, expression = nil) ⇒ CaseExpression
constructor
Create an object with the given conditions and default value.
Methods included from SubscriptMethods
Methods included from StringMethods
Methods included from OrderMethods
Methods included from ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from CastMethods
#cast, #cast_numeric, #cast_string
Methods included from BooleanMethods
Methods included from AliasMethods
Methods inherited from Expression
Constructor Details
#initialize(conditions, default, expression = nil) ⇒ CaseExpression
Create an object with the given conditions and default value.
478 479 480 481 |
# File 'lib/sequel/lib/sequel/sql.rb', line 478 def initialize(conditions, default, expression = nil) raise(Sequel::Error, 'CaseExpression conditions must be a hash or array of all two pairs') unless Sequel.condition_specifier?(conditions) @conditions, @default, @expression = conditions.to_a, default, expression end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
An array of all two pairs with the first element specifying the condition and the second element specifying the result.
468 469 470 |
# File 'lib/sequel/lib/sequel/sql.rb', line 468 def conditions @conditions end |
#default ⇒ Object (readonly)
The default value if no conditions are true
471 472 473 |
# File 'lib/sequel/lib/sequel/sql.rb', line 471 def default @default end |
#expression ⇒ Object (readonly)
The expression to test the conditions against
474 475 476 |
# File 'lib/sequel/lib/sequel/sql.rb', line 474 def expression @expression end |