Class: UriTemplate::Expression
- Inherits:
-
Object
- Object
- UriTemplate::Expression
- Defined in:
- lib/uri_template.rb
Instance Method Summary collapse
- #encode_set ⇒ Object
- #expand(params = {}) ⇒ Object
- #first_char ⇒ Object
-
#initialize(tree) ⇒ Expression
constructor
A new instance of Expression.
- #named? ⇒ Boolean
- #operator ⇒ Object
- #separator ⇒ Object
- #str_if_empty ⇒ Object
- #var_list ⇒ Object
Constructor Details
#initialize(tree) ⇒ Expression
Returns a new instance of Expression.
33 34 35 |
# File 'lib/uri_template.rb', line 33 def initialize(tree) @tree = tree end |
Instance Method Details
#encode_set ⇒ Object
82 83 84 85 86 |
# File 'lib/uri_template.rb', line 82 def encode_set set = Addressable::URI::CharacterClasses::UNRESERVED set += Addressable::URI::CharacterClasses::RESERVED if ["+", "#"].include? operator set end |
#expand(params = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/uri_template.rb', line 37 def (params = {}) out = var_list.map do |var| Var.new(self, var[:var]).value(params) end.compact return "" if out.empty? first_char + out.join(separator) end |
#first_char ⇒ Object
64 65 66 67 68 69 |
# File 'lib/uri_template.rb', line 64 def first_char case operator when nil, "+" then "" else operator end end |
#named? ⇒ Boolean
71 72 73 |
# File 'lib/uri_template.rb', line 71 def named? [";", "?", "&"].include? operator end |
#operator ⇒ Object
50 51 52 |
# File 'lib/uri_template.rb', line 50 def operator @tree[:operator] end |
#separator ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/uri_template.rb', line 54 def separator case operator when nil, "+", "#" then "," when "." then "." when "/" then "/" when ";" then ";" when "?", "&" then "&" end end |
#str_if_empty ⇒ Object
75 76 77 78 79 80 |
# File 'lib/uri_template.rb', line 75 def str_if_empty case operator when "?", "&" then "=" else "" end end |
#var_list ⇒ Object
46 47 48 |
# File 'lib/uri_template.rb', line 46 def var_list @tree[:var_list] end |