Class: KDL::Types::URLTemplate

Inherits:
Value::Custom show all
Defined in:
lib/kdl/types/url_template.rb

Defined Under Namespace

Classes: FragmentExpansion, LabelExpansion, ParameterExpansion, Parser, Part, PathExpansion, QueryContinuation, QueryExpansion, ReservedExpansion, StringExpansion, StringLiteral, Variable

Constant Summary collapse

UNRESERVED =
/[a-zA-Z0-9\-._~]/.freeze
RESERVED =
%r{[:/?#\[\]@!$&'()*+,;=]}.freeze

Constants inherited from Value

Value::Null

Instance Attribute Summary

Attributes inherited from Value::Custom

#oriinal_value

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value::Custom

#to_v1, #to_v2, #version

Methods inherited from Value

#==, #as_type, from, #initialize, #inspect, #method_missing, #respond_to_missing?, #stringify_value, #to_s, #to_v2, #version

Constructor Details

This class inherits a constructor from KDL::Value

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KDL::Value

Class Method Details

.call(value, type = 'url-template') ⇒ Object



11
12
13
14
15
16
# File 'lib/kdl/types/url_template.rb', line 11

def self.call(value, type = 'url-template')
  return nil unless value.is_a? ::KDL::Value::String

  parts = Parser.parse(value.value)
  new(parts, type: type)
end

Instance Method Details

#expand(variables) ⇒ Object



18
19
20
21
22
23
# File 'lib/kdl/types/url_template.rb', line 18

def expand(variables)
  result = value.map { |v| v.expand(variables) }.join
  parser = IRLReference::Parser.new(result)
  uri, * = parser.parse
  URI(uri)
end