Class: Qa::Authorities::LinkedData::Config
- Inherits:
-
Object
- Object
- Qa::Authorities::LinkedData::Config
- Extended by:
- ERB::Util
- 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, encode = false) ⇒ 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.
31 32 33 34 |
# File 'lib/qa/authorities/linked_data/config.rb', line 31 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.
26 27 28 |
# File 'lib/qa/authorities/linked_data/config.rb', line 26 def @authority_config end |
#authority_name ⇒ Object (readonly)
Returns the value of attribute authority_name.
25 26 27 |
# File 'lib/qa/authorities/linked_data/config.rb', line 25 def @authority_name end |
Class Method Details
.apply_replacements(url, config, replacements = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/qa/authorities/linked_data/config.rb', line 75 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, rep_pattern[:encode]) end url end |
.config_value(config, key) ⇒ Object
52 53 54 55 |
# File 'lib/qa/authorities/linked_data/config.rb', line 52 def self.config_value(config, key) return nil if config.nil? || !(config.key? key) config[key] end |
.predicate_uri(config, key) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/qa/authorities/linked_data/config.rb', line 57 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
69 70 71 72 73 |
# File 'lib/qa/authorities/linked_data/config.rb', line 69 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, encode = false) ⇒ Object
64 65 66 67 |
# File 'lib/qa/authorities/linked_data/config.rb', line 64 def self.replace_pattern(url, pattern, value, encode = false) value = url_encode(value).gsub(".", "%2E") if encode url.gsub("{?#{pattern}}", value) end |
Instance Method Details
#auth_config ⇒ String
Return the full configuration for an authority
46 47 48 49 50 |
# File 'lib/qa/authorities/linked_data/config.rb', line 46 def auth_config @authority_config ||= Qa::Authorities::LinkedData::AuthorityService.(@authority_name) raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data authority '#{@authority_name}'" if @authority_config.nil? @authority_config end |
#search ⇒ Object
36 37 38 |
# File 'lib/qa/authorities/linked_data/config.rb', line 36 def search @search ||= Qa::Authorities::LinkedData::SearchConfig.new(auth_config.fetch(:search)) end |
#term ⇒ Object
40 41 42 |
# File 'lib/qa/authorities/linked_data/config.rb', line 40 def term @term ||= Qa::Authorities::LinkedData::TermConfig.new(auth_config.fetch(:term)) end |