Class: MmEsSearch::Api::Facet::RangeFacetRow

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, MongoMapper::EmbeddedDocument
Defined in:
lib/mm_es_search/api/facet/range_facet_row.rb

Instance Method Summary collapse

Instance Method Details

#attributes(*args) ⇒ Object Also known as: to_mongo



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 22

def attributes(*args)
  attr = super
  attr.each_with_object({}) do |(key, value), hsh|
    hsh[key] = case value
    when ActiveSupport::TimeWithZone
      value.utc.to_time
    else
      value
    end
  end
end

#parentObject



83
84
85
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 83

def parent
  _parent_document
end

#render_numeric(pretty_print) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 54

def render_numeric(pretty_print)
  
  if pretty_print
    #TODO handle units (see http://bit.ly/rhx05t)
    from_formatted = number_to_human(from) if from?
    to_formatted = number_to_human(to) if to?
  else
    from_formatted = from if from?
    to_formatted = to if to?
  end
  
  if from? and to?
    "from #{from_formatted} to #{to_formatted}"
  elsif from?
    "#{from_formatted} or greater"
  else
    "upto #{to_formatted}"
  end
  
end

#to_english(pretty_print = true) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 46

def to_english(pretty_print = true)
  case from || to
  when Numeric
    render_numeric(pretty_print)
  when Time, DateTime
  end
end

#to_form_name(data_type) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 75

def to_form_name(data_type)
  params = []
  params << "data_type:#{data_type}"
  params << "from:#{from}" if from?
  params << "to:#{to}" if to?
  return params.join('&')
end

#to_range_itemObject



39
40
41
42
43
44
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 39

def to_range_item
  RangeItem.new(
    :from => from,
    :to   => to
  )
end

#zero_countObject



35
36
37
# File 'lib/mm_es_search/api/facet/range_facet_row.rb', line 35

def zero_count
  self.count = 0
end