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.


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

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

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields


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

def fields
  @fields
end

#keyObject (readonly)

Returns the value of attribute key


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

def key
  @key
end

#valuesObject (readonly)

Returns the value of attribute values


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

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.


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

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