Class: Qa::Authorities::LinkedData::Config
- Inherits:
-
Object
- Object
- Qa::Authorities::LinkedData::Config
- Defined in:
- lib/qa/authorities/linked_data/config.rb
Instance Attribute Summary collapse
-
#authority_config ⇒ Object
readonly
Returns the value of attribute authority_config.
-
#authority_name ⇒ Object
readonly
Returns the value of attribute authority_name.
Class Method Summary collapse
- .apply_replacements(url, config, replacements = {}) ⇒ Object
- .config_value(config, key) ⇒ Object
- .predicate_uri(config, key) ⇒ Object
- .process_subauthority(url, subauth_pattern, subauthorities, subauth_key) ⇒ Object
- .replace_pattern(url, pattern, value) ⇒ Object
Instance Method Summary collapse
-
#auth_config ⇒ String
Return the full configuration for an authority.
-
#initialize(auth_name) ⇒ Qa::Authorities::LinkedData::Config
constructor
Initialize to hold the configuration for the specifed authority.
- #search ⇒ Object
- #term ⇒ Object
Constructor Details
#initialize(auth_name) ⇒ Qa::Authorities::LinkedData::Config
Initialize to hold the configuration for the specifed authority. Configurations are defined in config/authorities/linked_data. See README for more information.
26 27 28 29 |
# File 'lib/qa/authorities/linked_data/config.rb', line 26 def initialize(auth_name) @authority_name = auth_name auth_config end |
Instance Attribute Details
#authority_config ⇒ Object (readonly)
Returns the value of attribute authority_config.
21 22 23 |
# File 'lib/qa/authorities/linked_data/config.rb', line 21 def @authority_config end |
#authority_name ⇒ Object (readonly)
Returns the value of attribute authority_name.
20 21 22 |
# File 'lib/qa/authorities/linked_data/config.rb', line 20 def @authority_name end |
Class Method Details
.apply_replacements(url, config, replacements = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/qa/authorities/linked_data/config.rb', line 69 def self.apply_replacements(url, config, replacements = {}) return url unless config.size.positive? config.each do |param_key, rep_pattern| s_param_key = param_key.to_s value = replacements[param_key] || replacements[s_param_key] || rep_pattern[:default] url = replace_pattern(url, param_key, value) end url end |
.config_value(config, key) ⇒ Object
47 48 49 50 |
# File 'lib/qa/authorities/linked_data/config.rb', line 47 def self.config_value(config, key) return nil if config.nil? || !(config.key? key) config[key] end |
.predicate_uri(config, key) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/qa/authorities/linked_data/config.rb', line 52 def self.predicate_uri(config, key) pred = config_value(config, key) pred_uri = nil pred_uri = RDF::URI(pred) unless pred.nil? || pred.length <= 0 pred_uri end |
.process_subauthority(url, subauth_pattern, subauthorities, subauth_key) ⇒ Object
63 64 65 66 67 |
# File 'lib/qa/authorities/linked_data/config.rb', line 63 def self.(url, subauth_pattern, , subauth_key) pattern = subauth_pattern[:pattern] value = [subauth_key] || subauth_pattern[:default] replace_pattern(url, pattern, value) end |
.replace_pattern(url, pattern, value) ⇒ Object
59 60 61 |
# File 'lib/qa/authorities/linked_data/config.rb', line 59 def self.replace_pattern(url, pattern, value) url.gsub("{?#{pattern}}", value) end |
Instance Method Details
#auth_config ⇒ String
Return the full configuration for an authority
41 42 43 44 45 |
# File 'lib/qa/authorities/linked_data/config.rb', line 41 def auth_config @authority_config ||= LINKED_DATA_AUTHORITIES_CONFIG[@authority_name] raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data authority '#{@authority_name}'" if @authority_config.nil? @authority_config end |
#search ⇒ Object
31 32 33 |
# File 'lib/qa/authorities/linked_data/config.rb', line 31 def search @search ||= Qa::Authorities::LinkedData::SearchConfig.new(auth_config.fetch(:search)) end |
#term ⇒ Object
35 36 37 |
# File 'lib/qa/authorities/linked_data/config.rb', line 35 def term @term ||= Qa::Authorities::LinkedData::TermConfig.new(auth_config.fetch(:term)) end |