class Dbee::Query::Field

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.

Attributes

aggregator[R]
display[R]
filters[R]
key_path[R]

Public Class Methods

new(key_path:, aggregator: nil, display: nil, filters: []) click to toggle source
# File lib/dbee/query/field.rb, line 29
def initialize(key_path:, aggregator: nil, display: nil, filters: [])
  raise ArgumentError, 'key_path is required' if key_path.to_s.empty?

  @aggregator = aggregator ? Aggregator.const_get(aggregator.to_s.upcase.to_sym) : nil
  @display    = (display.to_s.empty? ? key_path : display).to_s
  @filters    = Filters.array(filters).uniq
  @key_path   = KeyPath.get(key_path)

  freeze
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/dbee/query/field.rb, line 66
def <=>(other)
  "#{key_path}#{display}" <=> "#{other.key_path}#{other.display}"
end
==(other) click to toggle source
# File lib/dbee/query/field.rb, line 57
def ==(other)
  other.instance_of?(self.class) &&
    other.aggregator == aggregator &&
    other.key_path == key_path &&
    other.filters == filters &&
    other.display == display
end
Also aliased as: eql?
aggregator?() click to toggle source
# File lib/dbee/query/field.rb, line 44
def aggregator?
  !aggregator.nil?
end
eql?(other)
Alias for: ==
filters?() click to toggle source
# File lib/dbee/query/field.rb, line 40
def filters?
  filters.any?
end
hash() click to toggle source
# File lib/dbee/query/field.rb, line 48
def hash
  [
    aggregator,
    display,
    filters,
    key_path
  ].hash
end
key_paths() click to toggle source
# File lib/dbee/query/field.rb, line 70
def key_paths
  [key_path] + filters.map(&:key_path)
end