Class: Seaquel::Bit
- Inherits:
-
Object
- Object
- Seaquel::Bit
- Defined in:
- lib/seaquel/bit.rb
Overview
Represents a small bit of an SQL expression.
Instance Attribute Summary collapse
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
-
#str ⇒ Object
readonly
Returns the value of attribute str.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#at(target_precedence) ⇒ Object
Returns a string at given target_precedence.
-
#initialize(str, precedence) ⇒ Bit
constructor
A new instance of Bit.
-
#toplevel ⇒ Object
Returns the SQL that you would insert toplevel, meaning at a level where parens aren’t needed anymore.
Constructor Details
#initialize(str, precedence) ⇒ Bit
Returns a new instance of Bit.
11 12 13 14 |
# File 'lib/seaquel/bit.rb', line 11 def initialize str, precedence @str = str @precedence = precedence end |
Instance Attribute Details
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence.
9 10 11 |
# File 'lib/seaquel/bit.rb', line 9 def precedence @precedence end |
#str ⇒ Object (readonly)
Returns the value of attribute str.
8 9 10 |
# File 'lib/seaquel/bit.rb', line 8 def str @str end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 38 |
# File 'lib/seaquel/bit.rb', line 34 def == other return toplevel == other if other.kind_of?(String) super end |
#at(target_precedence) ⇒ Object
Returns a string at given target_precedence. If the precedence of this bit is lower than target_precedence, it will not be put in parenthesis.
19 20 21 22 23 24 25 |
# File 'lib/seaquel/bit.rb', line 19 def at target_precedence if precedence == :inf || target_precedence <= precedence @str else "(#{@str})" end end |
#toplevel ⇒ Object
Returns the SQL that you would insert toplevel, meaning at a level where parens aren’t needed anymore.
30 31 32 |
# File 'lib/seaquel/bit.rb', line 30 def toplevel str end |