Class: Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::Applicator
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::Applicator
- Defined in:
- lib/valkyrie/persistence/fedora/persister/orm_converter.rb
Overview
Class for mapping RDF statements in Property objects to Valkyrie Resource attributes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
Instance Method Summary collapse
-
#apply_to(hsh) ⇒ Hash
Apply as a single value by default, if there are multiple then create an array.
-
#blacklist ⇒ Array<String>
Retrieve a list of blacklisted URIs for predicates.
-
#blacklist?(key) ⇒ Boolean
Determines whether or not a key is blacklisted for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes).
-
#cast_array(values) ⇒ Array<Object>
Casts values into an Array.
-
#initialize(property) ⇒ Applicator
constructor
A new instance of Applicator.
-
#key ⇒ Symbol
Derive the key for the Valkyrie resource attribute from the RDF statement in the Property.
-
#namespaces ⇒ Array<String>
Retrieve a list of namespace URIs for predicates.
-
#values ⇒ RDF::URI
Access the object for the RDF statement.
Constructor Details
#initialize(property) ⇒ Applicator
Returns a new instance of Applicator.
514 515 516 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 514 def initialize(property) @property = property end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
509 510 511 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 509 def property @property end |
Instance Method Details
#apply_to(hsh) ⇒ Hash
Apply as a single value by default, if there are multiple then create an array. Done to support single values - if the resource is a Set or Array then it’ll cast the single value back to an array appropriately.
524 525 526 527 528 529 530 531 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 524 def apply_to(hsh) return if blacklist?(key) hsh[key.to_sym] = if hsh.key?(key.to_sym) Array.wrap(hsh[key.to_sym]) + cast_array(values) else values end end |
#blacklist ⇒ Array<String>
Retrieve a list of blacklisted URIs for predicates
568 569 570 571 572 573 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 568 def blacklist [ "http://fedora.info/definitions", "http://www.iana.org/assignments/relation/last" ] end |
#blacklist?(key) ⇒ Boolean
Determines whether or not a key is blacklisted for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes)
548 549 550 551 552 553 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 548 def blacklist?(key) blacklist.each do |blacklist_item| return true if key.start_with?(blacklist_item) end false end |
#cast_array(values) ⇒ Array<Object>
Casts values into an Array
558 559 560 561 562 563 564 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 558 def cast_array(values) if values.is_a?(Time) [values] else Array(values) end end |
#key ⇒ Symbol
Derive the key for the Valkyrie resource attribute from the RDF statement in the Property
535 536 537 538 539 540 541 542 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 535 def key predicate = statement.predicate.to_s key = schema.property_for(resource: nil, predicate: predicate) namespaces.each do |namespace| key = key.to_s.gsub(/^#{namespace}/, '') end key end |
#namespaces ⇒ Array<String>
Retrieve a list of namespace URIs for predicates
577 578 579 580 581 582 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 577 def namespaces [ "http://www.fedora.info/definitions/v4/", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ] end |
#values ⇒ RDF::URI
Access the object for the RDF statement
586 587 588 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 586 def values statement.object end |