Class: HttpRouter::Variable
- Inherits:
-
Object
- Object
- HttpRouter::Variable
- Defined in:
- lib/http_router/variable.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matches_with ⇒ Object
readonly
Returns the value of attribute matches_with.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #===(part) ⇒ Object
- #consume(match, parts) ⇒ Object
-
#initialize(router, name, matches_with = nil) ⇒ Variable
constructor
A new instance of Variable.
- #matches?(parts) ⇒ Boolean
Constructor Details
#initialize(router, name, matches_with = nil) ⇒ Variable
Returns a new instance of Variable.
5 6 7 8 9 |
# File 'lib/http_router/variable.rb', line 5 def initialize(router, name, matches_with = nil) @router = router @name = name @matches_with = matches_with end |
Instance Attribute Details
#matches_with ⇒ Object (readonly)
Returns the value of attribute matches_with.
3 4 5 |
# File 'lib/http_router/variable.rb', line 3 def matches_with @matches_with end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/http_router/variable.rb', line 3 def name @name end |
Instance Method Details
#===(part) ⇒ Object
24 25 26 |
# File 'lib/http_router/variable.rb', line 24 def ===(part) @matches_with.nil? end |
#consume(match, parts) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/http_router/variable.rb', line 15 def consume(match, parts) if @matches_with parts.replace(router.split(parts.whole_path[match.end(0), parts.whole_path.size])) match[0] else parts.shift end end |
#matches?(parts) ⇒ Boolean
11 12 13 |
# File 'lib/http_router/variable.rb', line 11 def matches?(parts) @matches_with.nil? or (@matches_with and match = @matches_with.match(parts.whole_path) and match.begin(0) == 0) ? match : nil end |