Method: Parse::Constraint.formatted_value

Defined in:
lib/parse/query/constraint.rb

.formatted_value(value) ⇒ Object

Returns a formatted value based on the data type.

Returns:

  • (Object)

    a formatted value based on the data type.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/parse/query/constraint.rb', line 104

def formatted_value(value)
  d = value
  d = { __type: Parse::Model::TYPE_DATE, iso: d.utc.iso8601(3) } if d.respond_to?(:utc)
  # if it responds to parse_date (most likely a time/date object), then call the conversion
  d = d.parse_date if d.respond_to?(:parse_date)
  # if it's not a Parse::Date, but still responds to iso8601, then do it manually
  if d.is_a?(Parse::Date) == false && d.respond_to?(:iso8601)
    d = { __type: Parse::Model::TYPE_DATE, iso: d.iso8601(3) }
  end
  d = d.pointer if d.respond_to?(:pointer) #simplified query object
  d = d.to_s if d.is_a?(Regexp)
  # d = d.pointer if d.is_a?(Parse::Object) #simplified query object
  #  d = d.compile
  if d.is_a?(Parse::Query)
    compiled = d.compile(encode: false, includeClassName: true)
    # compiled["className"] = d.table
    d = compiled
  end
  d
end