Method: Qa::LinkedData::DeepSortService#initialize

Defined in:
app/services/qa/linked_data/deep_sort_service.rb

#initialize(the_array, sort_key, preferred_language = nil) ⇒ Object

Returns instance of this class.

Examples:

the_array parameter

[
  {:uri=>[#<RDF::URI:0x3fcff54a829c URI:http://id.loc.gov/authorities/names/n2010043281>],
   :id=>[#<RDF::Literal:0x3fcff4a367b4("n 2010043281")>],
   :label=>[#<RDF::Literal:0x3fcff54a9a98("Valli, Sabrina"@en)>],
   :altlabel=>[],
   :sort=>[#<RDF::Literal:0x3fcff54b4c18("2")>]},
  {:uri=>[#<RDF::URI:0x3fcff54a829c URI:http://id.loc.gov/authorities/names/n201002344>],
   :id=>[#<RDF::Literal:0x3fcff4a367b4("n 201002344")>],
   :label=>[#<RDF::Literal:0x3fcff54a9a98("Cornell, Joseph"@en)>],
   :altlabel=>[],
   :sort=>[#<RDF::Literal:0x3fcff54b4c18("1")>]}
]

Parameters:

  • the (Array<Hash<Symbol,Array<RDF::Literal>>>)

    array of hashes to sort

  • the (sort_key)

    key in the hash on whose value the array will be sorted

  • preferred (Symbol)

    language to appear first in the list; defaults to no preference



22
23
24
# File 'app/services/qa/linked_data/deep_sort_service.rb', line 22

def initialize(the_array, sort_key, preferred_language = nil)
  @sortable_elements = the_array.map { |element| DeepSortElement.new(element, sort_key, preferred_language) }
end