Class: Sunspot::Search::StatsJsonRow

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/search/stats_json_row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, facet = nil, value = nil) ⇒ StatsJsonRow

:nodoc:



7
8
9
10
11
12
# File 'lib/sunspot/search/stats_json_row.rb', line 7

def initialize(data, facet = nil, value = nil) #:nodoc:
  @data, @facet, @value = data, facet, value
  @facet_fields = []
  @nested_key = data.keys.select { |k| data[k].is_a?(Hash) }.first
  @nested = recursive_nested_initialization(data) unless @nested_key.nil?
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/sunspot/search/stats_json_row.rb', line 4

def data
  @data
end

#instanceObject



58
59
60
61
62
63
# File 'lib/sunspot/search/stats_json_row.rb', line 58

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

#nestedObject (readonly)

Returns the value of attribute nested.



4
5
6
# File 'lib/sunspot/search/stats_json_row.rb', line 4

def nested
  @nested
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/sunspot/search/stats_json_row.rb', line 4

def value
  @value
end

Instance Method Details

#countObject



22
23
24
# File 'lib/sunspot/search/stats_json_row.rb', line 22

def count
  data['count']
end

#facet(name) ⇒ Object



48
49
50
# File 'lib/sunspot/search/stats_json_row.rb', line 48

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

#facetsObject



52
53
54
55
56
# File 'lib/sunspot/search/stats_json_row.rb', line 52

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

#inspectObject



65
66
67
68
69
70
# File 'lib/sunspot/search/stats_json_row.rb', line 65

def inspect
  "<Sunspot::Search::StatsJsonRow:#{value.inspect} min=#{min} max=#{max}"\
  " count=#{count} sum=#{sum} missing=#{missing} sum_of_squares=#{sum_of_squares}"\
  " mean=#{mean} standard_deviation=#{standard_deviation}"\
  " #{nested.nil? ? '' : "nested_count=#{nested.size}"}>"
end

#maxObject



18
19
20
# File 'lib/sunspot/search/stats_json_row.rb', line 18

def max
  data['max']
end

#meanObject Also known as: avg



39
40
41
# File 'lib/sunspot/search/stats_json_row.rb', line 39

def mean
  data['avg']
end

#minObject



14
15
16
# File 'lib/sunspot/search/stats_json_row.rb', line 14

def min
  data['min']
end

#missingObject



30
31
32
# File 'lib/sunspot/search/stats_json_row.rb', line 30

def missing
  data['missing']
end

#standard_deviationObject



44
45
46
# File 'lib/sunspot/search/stats_json_row.rb', line 44

def standard_deviation
  data['stddev']
end

#sumObject



26
27
28
# File 'lib/sunspot/search/stats_json_row.rb', line 26

def sum
  data['sum']
end

#sum_of_squaresObject Also known as: sumsq



34
35
36
# File 'lib/sunspot/search/stats_json_row.rb', line 34

def sum_of_squares
  data['sumsq']
end