Class: Couchbase::SearchFacet::SearchFacetDateRange

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/search_options.rb

Constant Summary collapse

DATE_FORMAT_RFC3339 =
"%Y-%m-%dT%H:%M:%S%:z".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) {|_self| ... } ⇒ SearchFacetDateRange

Returns a new instance of SearchFacetDateRange.

Parameters:

  • field (String)

    name of the field

Yields:

  • (_self)

Yield Parameters:



1302
1303
1304
1305
1306
1307
# File 'lib/couchbase/search_options.rb', line 1302

def initialize(field)
  super()
  @field = field
  @ranges = []
  yield self if block_given?
end

Instance Attribute Details

#fieldString (readonly)

Returns:

  • (String)


1296
1297
1298
# File 'lib/couchbase/search_options.rb', line 1296

def field
  @field
end

#sizeInteger

Returns:

  • (Integer)


1299
1300
1301
# File 'lib/couchbase/search_options.rb', line 1299

def size
  @size
end

Instance Method Details

#add(name, start_time, end_time) ⇒ Object

Parameters:

  • name (String)

    the name of the range

  • start_time (Time, String, nil)

    lower bound of the range (pass nil if there is no lower bound)

  • end_time (Time, String, nil)

    lower bound of the range (pass nil if there is no lower bound)



1314
1315
1316
1317
1318
# File 'lib/couchbase/search_options.rb', line 1314

def add(name, start_time, end_time)
  start_time = start_time.strftime(DATE_FORMAT_RFC3339) if start_time.respond_to?(:strftime)
  end_time = end_time.strftime(DATE_FORMAT_RFC3339) if end_time.respond_to?(:strftime)
  @ranges.append({name: name, start: start_time, end: end_time})
end

#to_json(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



1321
1322
1323
# File 'lib/couchbase/search_options.rb', line 1321

def to_json(*args)
  {field: field, size: size, date_ranges: @ranges}.to_json(*args)
end