Class: Qa::LinkedData::LanguageSortService
- Inherits:
-
Object
- Object
- Qa::LinkedData::LanguageSortService
- Defined in:
- app/services/qa/linked_data/language_sort_service.rb
Constant Summary collapse
- LANGUAGE_LOCALE_KEY_FOR_NO_LANGUAGE =
:NO_LANGUAGE
Instance Method Summary collapse
-
#initialize(literals, preferred_language = nil) ⇒ Object
constructor
Instance of this class.
-
#sort ⇒ Array<RDF::Literals] sorted version of literals
Sort the literals stored in this instance of the service.
-
#uniq_sorted_strings ⇒ Array<String>
Sort the literals and return as an array of strings with only unique literals and empty strings removed.
Constructor Details
#initialize(literals, preferred_language = nil) ⇒ Object
Returns instance of this class.
14 15 16 17 18 19 |
# File 'app/services/qa/linked_data/language_sort_service.rb', line 14 def initialize(literals, preferred_language = nil) @literals = literals @preferred_language = preferred_language @languages = [] @bins = {} end |
Instance Method Details
#sort ⇒ Array<RDF::Literals] sorted version of literals
Sort the literals stored in this instance of the service
23 24 25 26 27 28 29 30 |
# File 'app/services/qa/linked_data/language_sort_service.rb', line 23 def sort return literals unless literals.present? return @sorted_literals if @sorted_literals.present? parse_into_language_bins sort_languages sort_language_bins @sorted_literals = construct_sorted_literals end |
#uniq_sorted_strings ⇒ Array<String>
Sort the literals and return as an array of strings with only unique literals and empty strings removed
34 35 36 |
# File 'app/services/qa/linked_data/language_sort_service.rb', line 34 def uniq_sorted_strings sort.map(&:to_s).uniq.delete_if(&:blank?) end |