Class: Qa::IriTemplate::VariableMap
- Inherits:
-
Object
- Object
- Qa::IriTemplate::VariableMap
- Defined in:
- app/models/qa/iri_template/variable_map.rb
Constant Summary collapse
- TYPE =
"IriTemplateMapping".freeze
Instance Attribute Summary collapse
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Instance Method Summary collapse
-
#initialize(variable_map) ⇒ VariableMap
constructor
A new instance of VariableMap.
-
#parameter_value(sub_value = nil) ⇒ Object
Parameter and value to use in substitution, using default is one isn’t passed in.
-
#simple_value(sub_value = nil) ⇒ Object
Value to use in substitution, using default if one isn’t passed in.
Constructor Details
#initialize(variable_map) ⇒ VariableMap
Returns a new instance of VariableMap.
19 20 21 22 23 24 25 |
# File 'app/models/qa/iri_template/variable_map.rb', line 19 def initialize(variable_map) @variable = Qa::LinkedData::Config::Helper.fetch_required(variable_map, :variable, nil) @required = Qa::LinkedData::Config::Helper.fetch_boolean(variable_map, :required, nil) @default = Qa::LinkedData::Config::Helper.fetch(variable_map, :default, '').to_s @encode = Qa::LinkedData::Config::Helper.fetch_boolean(variable_map, :encode, false) @property = Qa::LinkedData::Config::Helper.fetch(variable_map, :property, 'hydra:freetextQuery') end |
Instance Attribute Details
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
9 10 11 |
# File 'app/models/qa/iri_template/variable_map.rb', line 9 def variable @variable end |
Instance Method Details
#parameter_value(sub_value = nil) ⇒ Object
Parameter and value to use in substitution, using default is one isn’t passed in. Use when template url specifies variable as ?var_name.
41 42 43 44 45 |
# File 'app/models/qa/iri_template/variable_map.rb', line 41 def parameter_value(sub_value = nil) simple_value = simple_value(sub_value) return '' if simple_value.blank? "#{variable}=#{simple_value}" end |
#simple_value(sub_value = nil) ⇒ Object
Value to use in substitution, using default if one isn’t passed in. Use when template url specifies variable as var_name.
30 31 32 33 34 35 36 |
# File 'app/models/qa/iri_template/variable_map.rb', line 30 def simple_value(sub_value = nil) raise Qa::IriTemplate::MissingParameter, "#{variable} is required, but missing" if sub_value.blank? && required? return default if sub_value.blank? sub_value = sub_value.to_s sub_value = ERB::Util.url_encode(sub_value).gsub(".", "%2E") if encode? sub_value end |