class ElasticsearchQuery::FilterFormatter::Range

Constants

INFINITY
NEGATIVE_INFINITY

Attributes

parser[RW]

Public Instance Methods

to_hash() click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 7
def to_hash
  return nil if all_the_values?

  range = {}.tap do |range|
    range[ :gte ] = beginning unless negative_infinity?( beginning )
    range[ :lt ]  = ending    unless infinity?( ending )
  end

  { range: { @name => range } }
end

Private Instance Methods

all_the_values?() click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 32
def all_the_values?
  infinity?( ending ) && negative_infinity?( beginning )
end
beginning() click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 24
def beginning
  @beginning ||= range.first
end
ending() click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 28
def ending
  @ending ||= range.last
end
infinity?( value ) click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 36
def infinity?( value )
  value == INFINITY
end
negative_infinity?( value ) click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 40
def negative_infinity?( value )
  value == NEGATIVE_INFINITY
end
range() click to toggle source
# File lib/elasticsearch_query/filter_formatter/range.rb, line 20
def range
  @range ||= self.class.parser.new( @value ).parse
end