Module: URITemplate::RFC6570::ClassMethods
- Included in:
- URITemplate::RFC6570
- Defined in:
- lib/uri_template/rfc6570.rb
Overview
The class methods for all rfc6570 templates.
Instance Method Summary collapse
-
#try_convert(x) ⇒ Object
Tries to convert the given param in to a instance of URITemplate::RFC6570 It basically passes thru instances of that class, parses strings and return nil on everything else.
-
#valid?(pattern) ⇒ Boolean
Tests whether a given pattern is a valid template pattern.
Instance Method Details
#try_convert(x) ⇒ Object
Tries to convert the given param in to a instance of URITemplate::RFC6570 It basically passes thru instances of that class, parses strings and return nil on everything else.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/uri_template/rfc6570.rb', line 257 def try_convert(x) if x.class == self return x elsif x.kind_of? String and valid? x return new(x) elsif x.kind_of? URITemplate::Colon return nil if x.tokens.any?{|tk| tk.kind_of? URITemplate::Colon::Token::Splat } return new( x.tokens.map{|tk| if tk.literal? Literal.new(tk.string) else Expression.new([[tk.variables.first, false, 0]]) end }) else return nil end end |
#valid?(pattern) ⇒ Boolean
Tests whether a given pattern is a valid template pattern.
281 282 283 |
# File 'lib/uri_template/rfc6570.rb', line 281 def valid?(pattern) URI === pattern end |