Class: Qa::IriTemplate::UrlConfig

Inherits:
Object
  • Object
show all
Defined in:
app/models/qa/iri_template/url_config.rb

Constant Summary collapse

TYPE =
"IriTemplate".freeze
CONTEXT =
"http://www.w3.org/ns/hydra/context.jsonld".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_config) ⇒ UrlConfig

Returns a new instance of UrlConfig.

Parameters:

  • url_config (Hash)

    configuration hash for the iri template

Options Hash (url_config):

  • :template (String)

    the URL template with variables for substitution (required)

  • :variable_representation (String)

    always “BasicRepresentation” # TODO what other values are supported and what do they mean

  • :mapping (Array<Hash>)

    array of maps for use with a template (required)



17
18
19
20
21
22
# File 'app/models/qa/iri_template/url_config.rb', line 17

def initialize(url_config)
  @url_config = url_config
  @template = Qa::LinkedData::Config::Helper.fetch_required(url_config, :template, nil)
  @mapping = extract_mapping
  @variable_representation = Qa::LinkedData::Config::Helper.fetch(url_config, :variable_representation, 'BasicRepresentation')
end

Instance Attribute Details

#mappingObject (readonly)

Array<Qa::IriTempalte::VariableMap>

array of maps for use with a template (required)



11
12
13
# File 'app/models/qa/iri_template/url_config.rb', line 11

def mapping
  @mapping
end

#templateObject (readonly)

String

the URL template with variables for substitution (required)



9
10
11
# File 'app/models/qa/iri_template/url_config.rb', line 9

def template
  @template
end

#variable_representationObject (readonly)

String

always “BasicRepresentation” # TODO what other values are supported and what do they mean



10
11
12
# File 'app/models/qa/iri_template/url_config.rb', line 10

def variable_representation
  @variable_representation
end

Instance Method Details

#extract_substitutions(substitutions) ⇒ HashWithIndifferentAccess

Selective extract substitution variable-value pairs from the provided substitutions.

Parameters:

  • full (Hash, ActionController::Parameters)

    set of passed in substitution values

Returns:

  • (HashWithIndifferentAccess)

    Only variable-value pairs for variables defined in the variable mapping.



27
28
29
30
31
32
33
# File 'app/models/qa/iri_template/url_config.rb', line 27

def extract_substitutions(substitutions)
  selected_substitutions = HashWithIndifferentAccess.new
  mapping.each do |m|
    selected_substitutions[m.variable] = substitutions[m.variable] if substitutions.key? m.variable
  end
  selected_substitutions
end