Class: Doze::URITemplate::QuadHexBytesVariable
- Inherits:
-
Variable
- Object
- Doze::URITemplate
- Variable
- Doze::URITemplate::QuadHexBytesVariable
- Defined in:
- lib/doze/uri_template.rb
Constant Summary collapse
- REGEXP =
"(?:/[0-9a-f]{2}){4}"
Constants inherited from Variable
Variable::BYTESIZE_METHOD, Variable::DEFAULT_REGEXP
Instance Attribute Summary
Attributes inherited from Variable
Instance Method Summary collapse
- #expand(vars) ⇒ Object
- #expand_code_fragment ⇒ Object
-
#initialize(name) ⇒ QuadHexBytesVariable
constructor
A new instance of QuadHexBytesVariable.
- #to_s ⇒ Object
- #translate_captured_string(string) ⇒ Object
Methods inherited from Variable
#partially_expand, #regexp_fragment, #variables
Methods inherited from Doze::URITemplate
#+, #anchored_regexp, compile, #compile_expand!, #inspect, #match, #match_with_trailing, #parts, #start_anchored_regexp, #with_prefix
Constructor Details
#initialize(name) ⇒ QuadHexBytesVariable
Returns a new instance of QuadHexBytesVariable.
118 119 120 |
# File 'lib/doze/uri_template.rb', line 118 def initialize(name) super(name, REGEXP) end |
Instance Method Details
#expand(vars) ⇒ Object
126 127 128 129 |
# File 'lib/doze/uri_template.rb', line 126 def (vars) hex = vars[@name].to_i.to_s(16).rjust(8,'0') "/#{hex[0..1]}/#{hex[2..3]}/#{hex[4..5]}/#{hex[6..7]}" end |
#expand_code_fragment ⇒ Object
131 132 133 |
# File 'lib/doze/uri_template.rb', line 131 def "/\#{hex=vars[#{@name.inspect}].to_i.to_s(16).rjust(8,'0');hex[0..1]}/\#{hex[2..3]}/\#{hex[4..5]}/\#{hex[6..7]}" end |
#to_s ⇒ Object
122 123 124 |
# File 'lib/doze/uri_template.rb', line 122 def to_s "{/#{@name}.quadhexbytes*}" end |
#translate_captured_string(string) ⇒ Object
135 136 137 |
# File 'lib/doze/uri_template.rb', line 135 def translate_captured_string(string) string.tr('/','').to_i(16) end |