Class: Hemp::Routing::RouteSplitter
- Defined in:
- lib/hemp/routing/route_split.rb
Instance Attribute Summary collapse
-
#split_route_path ⇒ Object
Returns the value of attribute split_route_path.
-
#url_regex_match ⇒ Object
Returns the value of attribute url_regex_match.
-
#url_variable_hash ⇒ Object
Returns the value of attribute url_variable_hash.
Instance Method Summary collapse
-
#initialize(split_route_path) ⇒ RouteSplitter
constructor
A new instance of RouteSplitter.
- #parse_regex_and_vars_from_route ⇒ Object
- #pick_out_url_variables ⇒ Object
- #save_variable_and_index(split_element, index) ⇒ Object
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_path ⇒ Object
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_match ⇒ Object
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_hash ⇒ Object
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_route ⇒ Object
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_variables ⇒ Object
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 |