Class: Valkyrie::Persistence::Solr::ORMConverter::RDFLiteralPropertyValue

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

Overview

Converts a stored language typed literal from two fields into one

{RDF::Literal}

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 Property has a Solr Document specifying the language tag or type for the value

Parameters:

Returns:

  • (Boolean)


141
142
143
144
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 141

def self.handles?(value)
  value.is_a?(Property) &&
    (value.document["#{value.key}_lang"] || value.document["#{value.key}_type"])
end

Instance Method Details

#datatypesArray<String>

Note:

this assumes that the substring “_type” is appended to the Solr field name specifying the supported datatypes

Access the datatypes within the Solr field value

Returns:

  • (Array<String>)


173
174
175
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 173

def datatypes
  value.document.fetch("#{value.key}_type", [])
end

#languagesArray<String>

Note:

this assumes that the substring “_lang” is appended to the Solr field name specifying the supported language tags

Access the languages within the Solr field value

Returns:

  • (Array<String>)


166
167
168
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 166

def languages
  value.document.fetch("#{value.key}_lang", [])
end

#resultArray<RDF::Literal>

Map the Property value to RDF literals This ensures that, if possible, RDF::Literals are (re)constructed using language tags and datatypes

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 149

def result
  value.value.each_with_index.map do |literal, idx|
    language = languages[idx]
    type = datatypes[idx]
    if language == "eng" && type == "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
      literal
    elsif language.present?
      RDF::Literal.new(literal, language: language, datatype: type)
    else
      RDF::Literal.new(literal, datatype: type)
    end
  end
end