Class: Valkyrie::Persistence::Solr::ModelConverter::SolrRow

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

Overview

Represents a key/value combination in the solr document, used for isolating logic around how to apply a value to a hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, fields:, values:) ⇒ SolrRow

Returns a new instance of SolrRow.

Parameters:

  • key (Symbol)

    Solr key.

  • fields (Array<Symbol>)

    Field suffixes to index into.

  • values (Array)

    Values to index into the given fields.



164
165
166
167
168
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 164

def initialize(key:, fields:, values:)
  @key = key
  @fields = fields
  @values = values
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



160
161
162
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 160

def fields
  @fields
end

#keyObject (readonly)

Returns the value of attribute key.



160
161
162
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 160

def key
  @key
end

#valuesObject (readonly)

Returns the value of attribute values.



160
161
162
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 160

def values
  @values
end

Instance Method Details

#apply_to(hsh) ⇒ Hash

Returns The updated solr hash.

Parameters:

  • hsh (Hash)

    The solr hash to apply to.

Returns:

  • (Hash)

    The updated solr hash.



172
173
174
175
176
177
178
179
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 172

def apply_to(hsh)
  return hsh if values.blank?
  fields.each do |field|
    hsh["#{key}_#{field}".to_sym] ||= []
    hsh["#{key}_#{field}".to_sym] += values
  end
  hsh
end