Class: Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::Applicator

Inherits:
Object
  • Object
show all
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

NonStringSingleApplicator, SingleApplicator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property) ⇒ Applicator

Returns a new instance of Applicator.

Parameters:



513
514
515
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 513

def initialize(property)
  @property = property
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



508
509
510
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 508

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.

Parameters:

  • hsh (Hash)

    a new or existing Hash of attribute for Valkyrie resource attributes

Returns:

  • (Hash)


523
524
525
526
527
528
529
530
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 523

def apply_to(hsh)
  return if deny?(key)
  hsh[key.to_sym] = if hsh.key?(key.to_sym)
                      Array.wrap(hsh[key.to_sym]) + cast_array(values)
                    else
                      values
                    end
end

#cast_array(values) ⇒ Array<Object>

Casts values into an Array

Parameters:

  • values (Object)

Returns:

  • (Array<Object>)


557
558
559
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 557

def cast_array(values)
  Array(values)
end

#deny?(key) ⇒ Boolean

Determines whether or not a key is on the deny list for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes)

Parameters:

  • key (Symbol)

Returns:

  • (Boolean)


547
548
549
550
551
552
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 547

def deny?(key)
  denylist.each do |denylist_item|
    return true if key.start_with?(denylist_item)
  end
  false
end

#denylistArray<String>

Retrieve a list of denied URIs for predicates

Returns:

  • (Array<String>)


563
564
565
566
567
568
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 563

def denylist
  [
    "http://fedora.info/definitions",
    "http://www.iana.org/assignments/relation/last"
  ]
end

#keySymbol

Derive the key for the Valkyrie resource attribute from the RDF statement in the Property

Returns:

  • (Symbol)


534
535
536
537
538
539
540
541
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 534

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

#namespacesArray<String>

Retrieve a list of namespace URIs for predicates

Returns:

  • (Array<String>)


572
573
574
575
576
577
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 572

def namespaces
  [
    "http://www.fedora.info/definitions/v4/",
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  ]
end

#valuesRDF::URI

Access the object for the RDF statement

Returns:



581
582
583
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 581

def values
  statement.object
end