Class: Hemp::Routing::RouteSplitter

Inherits:
Object
  • Object
show all
Defined in:
lib/hemp/routing/route_split.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(split_route_path) ⇒ RouteSplitter



6
7
8
9
10
# File 'lib/hemp/routing/route_split.rb', line 6

def initialize(split_route_path)
  @split_route_path = split_route_path
  @url_variable_hash = {}
  @url_regex_match = []
end

Instance Attribute Details

#split_route_pathObject

Returns the value of attribute split_route_path.



4
5
6
# File 'lib/hemp/routing/route_split.rb', line 4

def split_route_path
  @split_route_path
end

#url_regex_matchObject

Returns the value of attribute url_regex_match.



4
5
6
# File 'lib/hemp/routing/route_split.rb', line 4

def url_regex_match
  @url_regex_match
end

#url_variable_hashObject

Returns the value of attribute url_variable_hash.



4
5
6
# File 'lib/hemp/routing/route_split.rb', line 4

def url_variable_hash
  @url_variable_hash
end

Instance Method Details

#parse_regex_and_vars_from_routeObject



29
30
31
32
33
34
# File 'lib/hemp/routing/route_split.rb', line 29

def parse_regex_and_vars_from_route
  pick_out_url_variables
  regex_string = "^" << url_regex_match.join("/") << "/*$"

  [Regexp.new(regex_string), url_variable_hash]
end

#pick_out_url_variablesObject



12
13
14
15
16
17
18
19
20
# File 'lib/hemp/routing/route_split.rb', line 12

def pick_out_url_variables
  split_route_path.each_with_index do |split_element, index|
    if split_element.start_with?(":")
      url_regex_match << save_variable_and_index(split_element, index)
    else
      url_regex_match << split_element
    end
  end
end

#save_variable_and_index(split_element, index) ⇒ Object



22
23
24
25
26
27
# File 'lib/hemp/routing/route_split.rb', line 22

def save_variable_and_index(split_element, index)
  variable_key = split_element.delete(":")
  url_variable_hash[index] = variable_key.to_sym

  "[a-zA-Z0-9_]+"
end