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)
-
- (Object) try_convert(x)
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.
-
- (Boolean) valid?(pattern)
Tests whether a given pattern is a valid template pattern.
Instance Method Details
- (Object) try_convert(x)
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.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/uri_template/rfc6570.rb', line 228 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 |
- (Boolean) valid?(pattern)
Tests whether a given pattern is a valid template pattern.
252 253 254 |
# File 'lib/uri_template/rfc6570.rb', line 252 def valid?(pattern) URI === pattern end |