Class: RapidRunty::Router::RouteParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.options = url[:to]
rescue TypeError
  self.path = split_url(url)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/rapid_runty/router/route_parser.rb', line 8

def options
  @options
end

#pathObject

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

#placeholdersHash

Return the present placeholders for the url

Returns:

  • (Hash)

    of the placeholder key and its value.



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_sObject



17
18
19
# File 'lib/rapid_runty/router/route_parser.rb', line 17

def to_s
  '/' + path.join('/')
end