Class: Dbee::Query::Field
- Inherits:
-
Object
- Object
- Dbee::Query::Field
- Defined in:
- lib/dbee/query/field.rb
Overview
This class is an abstraction of the SELECT part of a SQL statement. The key_path is the relative path to the column while the display is the AS part of the SQL SELECT statement.
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#key_path ⇒ Object
readonly
Returns the value of attribute key_path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(key_path:, display: nil) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(key_path:, display: nil) ⇒ Field
Returns a new instance of Field.
20 21 22 23 24 25 26 27 |
# File 'lib/dbee/query/field.rb', line 20 def initialize(key_path:, display: nil) raise ArgumentError, 'key_path is required' if key_path.to_s.empty? @key_path = KeyPath.get(key_path) @display = (display.to_s.empty? ? key_path : display).to_s freeze end |
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display.
18 19 20 |
# File 'lib/dbee/query/field.rb', line 18 def display @display end |
#key_path ⇒ Object (readonly)
Returns the value of attribute key_path.
18 19 20 |
# File 'lib/dbee/query/field.rb', line 18 def key_path @key_path end |
Instance Method Details
#<=>(other) ⇒ Object
40 41 42 |
# File 'lib/dbee/query/field.rb', line 40 def <=>(other) "#{key_path}#{display}" <=> "#{other.key_path}#{other.display}" end |
#==(other) ⇒ Object Also known as: eql?
33 34 35 36 37 |
# File 'lib/dbee/query/field.rb', line 33 def ==(other) other.instance_of?(self.class) && other.key_path == key_path && other.display == display end |
#hash ⇒ Object
29 30 31 |
# File 'lib/dbee/query/field.rb', line 29 def hash "#{key_path}#{display}".hash end |