Class: Sunspot::FieldFactory::Coordinates

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

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, &block) ⇒ Coordinates

Returns a new instance of Coordinates.


130
131
132
133
134
135
136
# File 'lib/sunspot/field_factory.rb', line 130

def initialize(name = nil, &block)
  if block
    @data_extractor = DataExtractor::BlockExtractor.new(&block)
  else
    @data_extractor = DataExtractor::AttributeExtractor.new(name)
  end
end

Instance Method Details

#populate_document(document, model) ⇒ Object


138
139
140
141
142
143
144
# File 'lib/sunspot/field_factory.rb', line 138

def populate_document(document, model)
  if coordinates = @data_extractor.value_for(model)
    coordinates = Util::Coordinates.new(coordinates)
    document.add_field(:lat, coordinates.lat)
    document.add_field(:lng, coordinates.lng)
  end
end