Class: Valkyrie::Persistence::Solr::ORMConverter::EnumerableValue

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/orm_converter.rb

Overview

Class for handling multiple values in Solr fields

Instance Attribute Summary

Attributes inherited from ValueMapper

#calling_mapper, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueMapper

for, #initialize, register

Constructor Details

This class inherits a constructor from Valkyrie::ValueMapper

Class Method Details

.handles?(value) ⇒ Boolean

Determines whether or not a value behaves like an enumerable value

Parameters:

  • value (Object)

Returns:

  • (Boolean)


203
204
205
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 203

def self.handles?(value)
  value.respond_to?(:each)
end

Instance Method Details

#resultString+

Constructs SolrValue objects for each value and returns the String representation For cases where there is only one value, only a single String is returned

Returns:

  • (String, Array<String>)


210
211
212
213
214
215
216
217
218
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 210

def result
  if value.length == 1
    calling_mapper.for(value.first).result
  else
    value.map do |element|
      calling_mapper.for(element).result
    end
  end
end