Class: MarkLogic::Queries::BaseQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/marklogic/queries/base_query.rb

Instance Method Summary collapse

Instance Method Details

#add_sub_query(parent, query) ⇒ Object

Helper function to add a sub query into a parent query

Parameters:

Since:

  • 1.0.0


11
12
13
14
15
# File 'lib/marklogic/queries/base_query.rb', line 11

def add_sub_query(parent, query)
  query_json = query.to_json
  query_key = query_json.keys[0]
  parent[query_key] = query_json[query_key]
end

#query_value(original_value, type = nil) ⇒ Object

Returns the value of the query appropriately formatted

Parameters:

  • original_value (Any)

    The value to format

  • type (String) (defaults to: nil)

    The data type

Since:

  • 1.0.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/marklogic/queries/base_query.rb', line 23

def query_value(original_value, type = nil)
  if original_value.kind_of?(Array)
    value = original_value.map { |v| query_value(v) }.join(',')
  elsif original_value.kind_of?(TrueClass)
    value = 'fn:true()'
  elsif original_value.kind_of?(FalseClass)
    value = 'fn:false()'
  elsif original_value.kind_of?(ObjectId)
    value = %Q{"#{original_value.to_s}"}
  elsif original_value.kind_of?(String) || type == "string"
    value = %Q{"#{original_value}"}
  else
    value = original_value
  end
end