Sha256: 3b1c0f001cb2ecbdd800d758843c8e90ba0d54dacdff5e818119508e1c9fee4c

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 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=#{self.count} sum=#{sum} missing=#{missing} sum_of_squares=#{sum_of_squares}"\
        " mean=#{mean} standard_deviation=#{standard_deviation}>"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/search/stats_row.rb
sunspot-2.7.0 lib/sunspot/search/stats_row.rb
sunspot-2.6.0 lib/sunspot/search/stats_row.rb
sunspot-2.5.0 lib/sunspot/search/stats_row.rb
sunspot-2.4.0 lib/sunspot/search/stats_row.rb
sunspot-2.3.0 lib/sunspot/search/stats_row.rb