Sha256: 278e05e672759179620e46af2f2eef631a1ef9a973543d9e79b85394cc131df0

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

module Sunspot
  module Search
    class StatsRow
      attr_reader :data, :value
      attr_writer :instance #:nodoc:

      def initialize(data, facet = nil, value = nil) #:nodoc:
        @data, @facet, @value = data, facet, value
        @facet_fields = []
      end

      def min
        data['min']
      end

      def max
        data['max']
      end

      def count
        data['count']
      end

      def sum
        data['sum']
      end

      def missing
        data['missing']
      end

      def sum_of_squares
        data['sumOfSquares']
      end

      def mean
        data['mean']
      end

      def standard_deviation
        data['stddev']
      end

      def facet name
        facets.find { |facet| facet.field.name == name.to_sym }
      end

      def facets
        @facets ||= @facet_fields.map do |field|
          StatsFacet.new(field, data['facets'][field.indexed_name])
        end
      end

      def instance
        if !defined?(@instance)
          @facet.populate_instances
        end
        @instance
      end

      def inspect
        "<Sunspot::Search::StatsRow:#{value.inspect} min=#{min} max=#{max} count=#{count}>"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
sunspot-2.2.8 lib/sunspot/search/stats_row.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/search/stats_row.rb
sunspot-2.2.7 lib/sunspot/search/stats_row.rb
sunspot-2.2.6 lib/sunspot/search/stats_row.rb
sunspot-2.2.5 lib/sunspot/search/stats_row.rb
sunspot-2.2.4 lib/sunspot/search/stats_row.rb
sunspot-2.2.3 lib/sunspot/search/stats_row.rb
sunspot-2.2.2 lib/sunspot/search/stats_row.rb
sunspot-2.2.1 lib/sunspot/search/stats_row.rb
sunspot-2.2.0 lib/sunspot/search/stats_row.rb
sunspot-2.1.1 lib/sunspot/search/stats_row.rb