Class: Sunspot::Search::StatsJsonRow
- Inherits:
-
Object
- Object
- Sunspot::Search::StatsJsonRow
- Defined in:
- lib/sunspot/search/stats_json_row.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
- #instance ⇒ Object
-
#nested ⇒ Object
readonly
Returns the value of attribute nested.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #count ⇒ Object
- #facet(name) ⇒ Object
- #facets ⇒ Object
-
#initialize(data, facet = nil, value = nil) ⇒ StatsJsonRow
constructor
:nodoc:.
- #inspect ⇒ Object
- #max ⇒ Object
- #mean ⇒ Object (also: #avg)
- #min ⇒ Object
- #missing ⇒ Object
- #standard_deviation ⇒ Object
- #sum ⇒ Object
- #sum_of_squares ⇒ Object (also: #sumsq)
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/sunspot/search/stats_json_row.rb', line 4 def data @data end |
#instance ⇒ Object
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 |
#nested ⇒ Object (readonly)
Returns the value of attribute nested.
4 5 6 |
# File 'lib/sunspot/search/stats_json_row.rb', line 4 def nested @nested end |
#value ⇒ Object (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
#count ⇒ Object
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 |
#facets ⇒ Object
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 |
#inspect ⇒ Object
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 |
#max ⇒ Object
18 19 20 |
# File 'lib/sunspot/search/stats_json_row.rb', line 18 def max data['max'] end |
#mean ⇒ Object Also known as: avg
39 40 41 |
# File 'lib/sunspot/search/stats_json_row.rb', line 39 def mean data['avg'] end |
#min ⇒ Object
14 15 16 |
# File 'lib/sunspot/search/stats_json_row.rb', line 14 def min data['min'] end |
#missing ⇒ Object
30 31 32 |
# File 'lib/sunspot/search/stats_json_row.rb', line 30 def missing data['missing'] end |
#standard_deviation ⇒ Object
44 45 46 |
# File 'lib/sunspot/search/stats_json_row.rb', line 44 def standard_deviation data['stddev'] end |
#sum ⇒ Object
26 27 28 |
# File 'lib/sunspot/search/stats_json_row.rb', line 26 def sum data['sum'] end |
#sum_of_squares ⇒ Object Also known as: sumsq
34 35 36 |
# File 'lib/sunspot/search/stats_json_row.rb', line 34 def sum_of_squares data['sumsq'] end |