Class: Valkyrie::Persistence::Solr::ORMConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::ORMConverter
show all
- Defined in:
- lib/valkyrie/persistence/solr/orm_converter.rb
Overview
Responsible for converting hashes from Solr into a Resource
Defined Under Namespace
Classes: BooleanValue, DateTimeValue, EnumerableValue, IDValue, IntegerValue, NestedEnumerable, NestedResourceConverter, NestedResourceHash, NestedResourceID, NestedResourceLiteral, NestedResourceURI, NestedResourceValue, Property, PropertyValue, RDFLiteralPropertyValue, SolrValue, URIValue
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(solr_document) ⇒ ORMConverter
6
7
8
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 6
def initialize(solr_document)
@solr_document = solr_document
end
|
Instance Attribute Details
#solr_document ⇒ Object
Returns the value of attribute solr_document.
5
6
7
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 5
def solr_document
@solr_document
end
|
Instance Method Details
#attribute_hash ⇒ Object
42
43
44
45
46
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 42
def attribute_hash
build_literals(strip_tsim(solr_document.select do |k, _v|
k.end_with?("tsim")
end))
end
|
#attributes ⇒ Object
26
27
28
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 26
def attributes
attribute_hash.merge("id" => id, internal_resource: internal_resource, created_at: created_at, updated_at: updated_at)
end
|
#build_literals(hsh) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 65
def build_literals(hsh)
hsh.each_with_object({}) do |(key, value), output|
next if key.end_with?("_lang")
next if key.end_with?("_type")
output[key] = SolrValue.for(Property.new(key, value, hsh)).result
end
end
|
#convert! ⇒ Object
10
11
12
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 10
def convert!
resource
end
|
#created_at ⇒ Object
30
31
32
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 30
def created_at
DateTime.parse(solr_document.fetch("created_at_dtsi").to_s).utc
end
|
#id ⇒ Object
38
39
40
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 38
def id
solr_document.fetch('id').sub(/^id-/, '')
end
|
#internal_resource ⇒ Object
22
23
24
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 22
def internal_resource
solr_document.fetch(Valkyrie::Persistence::Solr::Queries::MODEL).first
end
|
#resource ⇒ Object
14
15
16
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 14
def resource
resource_klass.new(attributes.symbolize_keys.merge(new_record: false))
end
|
#resource_klass ⇒ Object
18
19
20
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 18
def resource_klass
internal_resource.constantize
end
|
#strip_tsim(hsh) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 48
def strip_tsim(hsh)
Hash[
hsh.map do |k, v|
[k.sub("_tsim", ""), v]
end
]
end
|
#updated_at ⇒ Object
34
35
36
|
# File 'lib/valkyrie/persistence/solr/orm_converter.rb', line 34
def updated_at
DateTime.parse(solr_document["timestamp"] || solr_document.fetch("created_at_dtsi").to_s).utc
end
|