Class: Dbee::Query::Field

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(key_path:, display: nil) ⇒ Field

Returns a new instance of Field.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
# File 'lib/dbee/query/field.rb', line 22

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

#displayObject (readonly)

Returns the value of attribute display.



20
21
22
# File 'lib/dbee/query/field.rb', line 20

def display
  @display
end

#key_pathObject (readonly)

Returns the value of attribute key_path.



20
21
22
# File 'lib/dbee/query/field.rb', line 20

def key_path
  @key_path
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



35
36
37
# File 'lib/dbee/query/field.rb', line 35

def ==(other)
  other.key_path == key_path && other.display == display
end

#hashObject



31
32
33
# File 'lib/dbee/query/field.rb', line 31

def hash
  "#{key_path}#{display}".hash
end