Class: HttpRouter::Node::Regex

### Home Classes Methods

### In Files

- lib/http_router/node/regex.rb

### Parent

HttpRouter::Node

### Methods

- ::new
- #node_to_code
- #param_capturing_code
- #to_code
- #usable?

### Files

- LICENSE

### Class/Module Index

Quicksearch

- HttpRouter
- HttpRouter::GenerationHelper
- HttpRouter::Generator
- HttpRouter::Generator::PathGenerator
- HttpRouter::Node
- HttpRouter::Node::AbstractRequestNode
- HttpRouter::Node::FreeRegex
- HttpRouter::Node::Glob
- HttpRouter::Node::GlobRegex
- HttpRouter::Node::Host
- HttpRouter::Node::Lookup
- HttpRouter::Node::Path
- HttpRouter::Node::Regex
- HttpRouter::Node::RequestMethod
- HttpRouter::Node::Root
- HttpRouter::Node::Scheme
- HttpRouter::Node::SpanningRegex
- HttpRouter::Node::UserAgent
- HttpRouter::Node::Variable
- HttpRouter::RegexRouteGeneration
- HttpRouter::Request
- HttpRouter::Response
- HttpRouter::Route
- HttpRouter::RouteHelper
- HttpRouter::Util

No matching classes.

# HttpRouter::Node::Regex

### Attributes

capturing_indicies[R]
matcher[R]
ordered_indicies[R]
splitting_indicies[R]

### Public Class Methods

new(router, parent, matcher, capturing_indicies, splitting_indicies = nil) click to toggle source

    # File lib/http_router/node/regex.rb, line 7
    def initialize(router, parent, matcher, capturing_indicies, splitting_indicies = nil)
      @matcher, @capturing_indicies, @splitting_indicies = matcher, capturing_indicies, splitting_indicies
      @ordered_indicies = []
      @ordered_indicies.concat(capturing_indicies.map{|i| [i, :capture]}) if capturing_indicies
      @ordered_indicies.concat(splitting_indicies.map{|i| [i, :split]}) if splitting_indicies
      @ordered_indicies.sort!
      super(router, parent)
    end

### Public Instance Methods

node_to_code() click to toggle source
Alias for: to_code
param_capturing_code() click to toggle source

    # File lib/http_router/node/regex.rb, line 30
    def param_capturing_code
      @ordered_indicies.map{|(i, type)|
        case type
        when :capture then "request.params << match[#{i}]\n"
        when :split   then "request.params << match[#{i}].split(/\\//)\n"
        end
      }.join("")
    end

to_code() click to toggle source

    # File lib/http_router/node/regex.rb, line 20
    def to_code
      params_size = @splitting_indicies.size + @capturing_indicies.size
      "if match = #{@matcher.inspect}.match(request.path.first) and match.begin(0).zero?
        part = request.path.shift\n" << param_capturing_code <<
        "#{super}
        request.path.unshift part
        #{params_size == 1 ? "request.params.pop" : "request.params.slice!(#{-params_size}, #{params_size})"}
      end"
    end

Also aliased as: node_to_code
usable?(other) click to toggle source

    # File lib/http_router/node/regex.rb, line 16
    def usable?(other)
      other.class == self.class && other.matcher == matcher && other.splitting_indicies == splitting_indicies && other.capturing_indicies == capturing_indicies
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.