Class: LcpRuby::Search::QueryLanguageSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/search/query_language_serializer.rb

Constant Summary collapse

OPERATOR_TO_QL =
{
  "eq" => "=",
  "not_eq" => "!=",
  "gt" => ">",
  "gteq" => ">=",
  "lt" => "<",
  "lteq" => "<=",
  "cont" => "~",
  "not_cont" => "!~",
  "start" => "^",
  "not_start" => "!^",
  "end" => "$",
  "not_end" => "!$",
  "in" => "in",
  "not_in" => "not in",
  "between" => "between",
  "null" => "is null",
  "not_null" => "is not null",
  "present" => "is present",
  "blank" => "is blank",
  "true" => "is true",
  "not_true" => "is not true",
  "false" => "is false",
  "not_false" => "is not false",
  "last_n_days" => "in",
  "this_week" => "is this_week",
  "this_month" => "is this_month",
  "this_quarter" => "is this_quarter",
  "this_year" => "is this_year",
  "scope" => nil # Scope refs handled specially
}.freeze
NO_VALUE_OPERATORS =
OperatorRegistry::NO_VALUE_OPERATORS.map(&:to_s).freeze

Class Method Summary collapse

Class Method Details

.serialize(tree) ⇒ String

Serialize a condition tree to QL text. Supports both recursive format { “combinator”, “children” } and legacy format { “combinator”, “conditions”, “groups” }.

Parameters:

  • tree (Hash)

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
# File 'lib/lcp_ruby/search/query_language_serializer.rb', line 43

def self.serialize(tree)
  return "" if tree.blank?

  # Detect legacy format and delegate
  if tree.key?("conditions") && !tree.key?("children")
    return serialize_legacy(tree)
  end

  serialize_node(tree, parent_combinator: nil)
end