Class: Qa::LinkedData::DeepSortService
- Inherits:
-
Object
- Object
- Qa::LinkedData::DeepSortService
- Defined in:
- app/services/qa/linked_data/deep_sort_service.rb
Instance Method Summary collapse
-
#initialize(the_array, sort_key, preferred_language = nil) ⇒ Object
constructor
Instance of this class.
-
#sort ⇒ Object
Sort an array of hash on the specified sort key.
Constructor Details
#initialize(the_array, sort_key, preferred_language = nil) ⇒ Object
Returns instance of this class.
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 |
Instance Method Details
#sort ⇒ Object
Sort an array of hash on the specified sort key. The value in the hash at sort key is expected to be an array with one or more values that are RDF::Literals that translate to a number (e.g. 2), a string number (e.g. “3”), a string (e.g. “hello”), or a language qualified string (e.g. “hello”@en). The sort occurs in the following precedence.
-
preference for numeric sort (if only one value each and both are integers or a string that can be converted to an integer)
-
single value sort (if only one value each and at least one is not an integer)
-
multiple values sort (if either has multiple values)
47 48 49 |
# File 'app/services/qa/linked_data/deep_sort_service.rb', line 47 def sort @sortable_elements.sort.map(&:element) end |