Class: Stone::Query
- Inherits:
-
Object
- Object
- Stone::Query
- Defined in:
- lib/stone/query.rb
Overview
Represents a single query condition
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#op ⇒ Object
Returns the value of attribute op.
Instance Method Summary collapse
-
#expression_for(arg) ⇒ Object
- Builds an expression from the conditions given during first or all === Parameters
arg
-
Some conditional argument.
- Builds an expression from the conditions given during first or all === Parameters
-
#initialize(field, op) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(field, op) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stone/query.rb', line 7 def initialize(field,op) self.field = field self.op = case op when :gt ".>" when :lt ".<" when :gte ".>=" when :lte ".<=" when :includes ".include?" when :matches ".=~" when :equals ".==" when :not ".!=" end end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
5 6 7 |
# File 'lib/stone/query.rb', line 5 def field @field end |
#op ⇒ Object
Returns the value of attribute op.
5 6 7 |
# File 'lib/stone/query.rb', line 5 def op @op end |
Instance Method Details
#expression_for(arg) ⇒ Object
Builds an expression from the conditions given during first or all
Parameters
arg
-
Some conditional argument
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stone/query.rb', line 32 def expression_for(arg) if arg.is_a? String "#{self.field}#{self.op}('#{arg}')" elsif arg.is_a? Regexp "#{self.field}#{self.op}(#{arg.inspect})" elsif arg.is_a? Date "#{self.field}#{self.op}(DateTime.parse(\"#{arg}\"))" else "#{self.field}#{self.op}(#{arg})" end end |