Class: RapidRunty::Router::RouteParser
- Defined in:
- lib/rapid_runty/router/route_parser.rb
Overview
Parses the route, extracts and return the various important parts of the url.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(url) ⇒ RouteParser
constructor
A new instance of RouteParser.
-
#placeholders ⇒ Hash
Return the present placeholders for the url.
- #to_s ⇒ Object
Constructor Details
#initialize(url) ⇒ RouteParser
Returns a new instance of RouteParser.
10 11 12 13 14 15 |
# File 'lib/rapid_runty/router/route_parser.rb', line 10 def initialize(url) self.path = split_url(url[:url]) self. = url[:to] rescue TypeError self.path = split_url(url) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/rapid_runty/router/route_parser.rb', line 8 def @options end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/rapid_runty/router/route_parser.rb', line 8 def path @path end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 39 |
# File 'lib/rapid_runty/router/route_parser.rb', line 35 def ==(other) is_match = size_match?(other) && path_match?(other) @match = other if is_match is_match end |
#placeholders ⇒ Hash
Return the present placeholders for the url
25 26 27 28 29 30 31 32 33 |
# File 'lib/rapid_runty/router/route_parser.rb', line 25 def placeholders return {} unless @match placeholders = {} path.each_with_index do |part, i| placeholders[part.delete(':').to_s] = @match.path[i] if part[0] == ':' end placeholders end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/rapid_runty/router/route_parser.rb', line 17 def to_s '/' + path.join('/') end |