Class: Valkyrie::Persistence::Solr::ORMConverter::RDFLiteralPropertyValue
- Inherits:
-
ValueMapper
- Object
- ValueMapper
- Valkyrie::Persistence::Solr::ORMConverter::RDFLiteralPropertyValue
- 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
Class Method Summary collapse
-
.handles?(value) ⇒ Boolean
Determines whether or not a Property has a Solr Document specifying the language tag or type for the value.
Instance Method Summary collapse
-
#datatypes ⇒ Array<String>
Access the datatypes within the Solr field value.
-
#languages ⇒ Array<String>
Access the languages within the Solr field value.
-
#result ⇒ Array<RDF::Literal>
Map the Property value to RDF literals This ensures that, if possible, RDF::Literals are (re)constructed using language tags and datatypes.
Methods inherited from ValueMapper
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
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
#datatypes ⇒ Array<String>
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
173 174 175 |
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 173 def datatypes value.document.fetch("#{value.key}_type", []) end |
#languages ⇒ Array<String>
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
166 167 168 |
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 166 def languages value.document.fetch("#{value.key}_lang", []) end |
#result ⇒ Array<RDF::Literal>
Map the Property value to RDF literals This ensures that, if possible, RDF::Literals are (re)constructed using language tags and datatypes
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 |