Class: Qa::Authorities::LinkedData::SearchConfig
- Inherits:
-
Object
- Object
- Qa::Authorities::LinkedData::SearchConfig
- Defined in:
- lib/qa/authorities/linked_data/config/search_config.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
Instance Method Summary collapse
-
#context_map ⇒ Qa::LinkedData::Config::ContextMap
Return the context map if it is defined.
- #info ⇒ Object
-
#initialize(config, prefixes = {}, full_config = nil) ⇒ SearchConfig
constructor
A new instance of SearchConfig.
-
#language ⇒ String
Return the preferred language for literal value selection for search query.
-
#qa_replacement_patterns ⇒ Hash
Return parameters that are supported directly by QA api (e.g. q, subauth, lang).
-
#requested_records_parameter ⇒ String
Name of parameter holding number of requested records.
-
#results ⇒ Hash, NilClass
Return results ldpaths or predicates if specified.
-
#results_altlabel_ldpath ⇒ String
Return results altlabel_ldpath.
-
#results_altlabel_predicate ⇒ String
Return results altlabel_predicate.
-
#results_id_ldpath ⇒ String
Return results id_ldpath.
-
#results_id_predicate ⇒ String
Return results id_predicate.
-
#results_label_ldpath ⇒ String
Return results label_ldpath.
-
#results_label_predicate(suppress_deprecation_warning: false) ⇒ String
Return results label_predicate.
-
#results_sort_ldpath ⇒ String
Return results sort_ldpath.
-
#results_sort_predicate ⇒ String
Return results sort_predicate.
-
#start_record_parameter ⇒ String
Name of parameter holding start record number.
-
#subauthorities ⇒ Hash
Return the list of subauthorities for search query.
-
#subauthorities? ⇒ True|False
Are there subauthorities configured for search query?.
-
#subauthority?(subauth_name) ⇒ True|False
Is a specific subauthority configured for search query?.
-
#subauthority_count ⇒ Integer
Return the number of subauthorities defined for search query.
-
#supports_context? ⇒ True|False
Does this authority configuration support additional context in search results?.
-
#supports_language_parameter? ⇒ Boolean
True if supports language parameter; otherwise, false.
-
#supports_search? ⇒ Boolean
Does this authority configuration have search defined?.
-
#supports_sort? ⇒ True|False
Does this authority configuration support sorting of search results?.
-
#supports_subauthorities? ⇒ Boolean
True if supports subauthorities; otherwise, false.
-
#total_count_ldpath ⇒ String
Ldpath of the triple that holds the total number of available records for a search.
-
#url_config ⇒ Qa::IriTemplate::UrlConfig
Return search url template defined in the configuration for this authority.
Constructor Details
#initialize(config, prefixes = {}, full_config = nil) ⇒ SearchConfig
Returns a new instance of SearchConfig.
16 17 18 19 20 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 16 def initialize(config, prefixes = {}, full_config = nil) @search_config = config @prefixes = prefixes @full_config = full_config end |
Instance Attribute Details
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
8 9 10 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 8 def prefixes @prefixes end |
Instance Method Details
#context_map ⇒ Qa::LinkedData::Config::ContextMap
Return the context map if it is defined
138 139 140 141 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 138 def context_map return nil unless search_config.key?(:context) @context_map ||= Qa::LinkedData::Config::ContextMap.new(search_config.fetch(:context), prefixes) end |
#info ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 201 def info return [] unless supports_search? auth_name = .downcase.to_s language = Qa::LinkedData::LanguageService.preferred_language(authority_language: language).map(&:to_s) details = (auth_name, language) .each_key { |subauth_name| details << (auth_name, subauth_name.downcase.to_s, language) } details end |
#language ⇒ String
Return the preferred language for literal value selection for search query. This is the default used for this authority if the user does not pass in a language. Only applies if the authority provides language encoded literals.
38 39 40 41 42 43 44 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 38 def language return @language unless @language.nil? lang = search_config[:language] return nil if lang.nil? lang = [lang] if lang.is_a? String @language = lang.collect(&:to_sym) end |
#qa_replacement_patterns ⇒ Hash
Return parameters that are supported directly by QA api (e.g. q, subauth, lang)
145 146 147 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 145 def qa_replacement_patterns search_config.fetch(:qa_replacement_patterns, {}) end |
#requested_records_parameter ⇒ String
Returns name of parameter holding number of requested records.
191 192 193 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 191 def requested_records_parameter qa_replacement_patterns.key?(:requested_records) ? qa_replacement_patterns[:requested_records] : nil end |
#results ⇒ Hash, NilClass
Return results ldpaths or predicates if specified
48 49 50 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 48 def results search_config[:results] end |
#results_altlabel_ldpath ⇒ String
Return results altlabel_ldpath
90 91 92 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 90 def results_altlabel_ldpath Config.config_value(results, :altlabel_ldpath) end |
#results_altlabel_predicate ⇒ String
Return results altlabel_predicate
96 97 98 99 100 101 102 103 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 96 def results_altlabel_predicate Qa.deprecation_warning( in_msg: 'Qa::Authorities::LinkedData::SearchConfig', msg: "`results_altlabel_predicate` is deprecated; use `results_altlabel_ldpath` by updating linked data " \ "search config results in authority #{} to specify as `altlabel_ldpath`" ) Config.predicate_uri(results, :altlabel_predicate) end |
#results_id_ldpath ⇒ String
Return results id_ldpath
54 55 56 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 54 def results_id_ldpath Config.config_value(results, :id_ldpath) end |
#results_id_predicate ⇒ String
Return results id_predicate
60 61 62 63 64 65 66 67 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 60 def results_id_predicate Qa.deprecation_warning( in_msg: 'Qa::Authorities::LinkedData::SearchConfig', msg: "`results_id_predicate` is deprecated; use `results_id_ldpath` by updating linked data search config results " \ "in authority #{} to specify as `id_ldpath`" ) Config.predicate_uri(results, :id_predicate) end |
#results_label_ldpath ⇒ String
Return results label_ldpath
71 72 73 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 71 def results_label_ldpath Config.config_value(results, :label_ldpath) end |
#results_label_predicate(suppress_deprecation_warning: false) ⇒ String
Return results label_predicate
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 77 def results_label_predicate(suppress_deprecation_warning: false) unless suppress_deprecation_warning Qa.deprecation_warning( in_msg: 'Qa::Authorities::LinkedData::SearchConfig', msg: "`results_label_predicate` is deprecated; use `results_label_ldpath` by updating linked data search config results " \ "in authority #{} to specify as `label_ldpath`" ) end Config.predicate_uri(results, :label_predicate) end |
#results_sort_ldpath ⇒ String
Return results sort_ldpath
114 115 116 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 114 def results_sort_ldpath Config.config_value(results, :sort_ldpath) end |
#results_sort_predicate ⇒ String
Return results sort_predicate
120 121 122 123 124 125 126 127 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 120 def results_sort_predicate Qa.deprecation_warning( in_msg: 'Qa::Authorities::LinkedData::SearchConfig', msg: "`results_sort_predicate` is deprecated; use `results_sort_ldpath` by updating linked data " \ "search config results in authority #{} to specify as `sort_ldpath`" ) Config.predicate_uri(results, :sort_predicate) end |
#start_record_parameter ⇒ String
Returns name of parameter holding start record number.
186 187 188 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 186 def start_record_parameter qa_replacement_patterns.key?(:start_record) ? qa_replacement_patterns[:start_record] : nil end |
#subauthorities ⇒ Hash
Return the list of subauthorities for search query
180 181 182 183 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 180 def @subauthorities ||= {} if search_config.nil? || !(search_config.key? :subauthorities) @subauthorities ||= search_config.fetch(:subauthorities) end |
#subauthorities? ⇒ True|False
Are there subauthorities configured for search query?
161 162 163 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 161 def .positive? end |
#subauthority?(subauth_name) ⇒ True|False
Is a specific subauthority configured for search query?
167 168 169 170 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 167 def (subauth_name) subauth_name = subauth_name.to_sym if subauth_name.is_a? String .key? subauth_name end |
#subauthority_count ⇒ Integer
Return the number of subauthorities defined for search query
174 175 176 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 174 def .size end |
#supports_context? ⇒ True|False
Does this authority configuration support additional context in search results?
131 132 133 134 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 131 def supports_context? return true if context_map.present? false end |
#supports_language_parameter? ⇒ Boolean
Returns true if supports language parameter; otherwise, false.
155 156 157 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 155 def supports_language_parameter? qa_replacement_patterns.key? :lang end |
#supports_search? ⇒ Boolean
Does this authority configuration have search defined?
24 25 26 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 24 def supports_search? search_config.present? end |
#supports_sort? ⇒ True|False
Does this authority configuration support sorting of search results?
107 108 109 110 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 107 def supports_sort? return true unless results_sort_ldpath.present? || !results_sort_predicate.present? false end |
#supports_subauthorities? ⇒ Boolean
Returns true if supports subauthorities; otherwise, false.
150 151 152 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 150 def qa_replacement_patterns.key?(:subauth) && end |
#total_count_ldpath ⇒ String
Returns ldpath of the triple that holds the total number of available records for a search.
197 198 199 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 197 def total_count_ldpath search_config.key?(:total_count_ldpath) ? search_config[:total_count_ldpath] : nil end |
#url_config ⇒ Qa::IriTemplate::UrlConfig
Return search url template defined in the configuration for this authority.
30 31 32 |
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 30 def url_config @url_config ||= Qa::IriTemplate::UrlConfig.new(search_config[:url]) if supports_search? end |