Class: Journey::Path::Pattern

### Home Classes Methods

### In Files

- lib/journey/path/pattern.rb

### Parent

Object

### Namespace

- CLASS Journey::Path::Pattern::MatchData

### Methods

- ::new
- #=~
- #ast
- #match
- #names
- #optional_names
- #required_names
- #source
- #to_regexp

### Files

- CHANGELOG.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Journey
- Journey::Formatter
- Journey::GTG
- Journey::GTG::Builder
- Journey::GTG::MatchData
- Journey::GTG::Simulator
- Journey::GTG::TransitionTable
- Journey::NFA
- Journey::NFA::Builder
- Journey::NFA::MatchData
- Journey::NFA::Simulator
- Journey::NFA::TransitionTable
- Journey::NFA::Visitor
- Journey::Nodes
- Journey::Nodes::Binary
- Journey::Nodes::Cat
- Journey::Nodes::Dummy
- Journey::Nodes::Group
- Journey::Nodes::Literal
- Journey::Nodes::Or
- Journey::Nodes::Star
- Journey::Nodes::Symbol
- Journey::Nodes::Terminal
- Journey::Nodes::Unary
- Journey::Parser
- Journey::Path
- Journey::Path::Pattern
- Journey::Path::Pattern::MatchData
- Journey::Route
- Journey::Router
- Journey::Router::RoutingError
- Journey::Router::Strexp
- Journey::Router::Utils
- Journey::Router::Utils::UriEscape
- Journey::Routes
- Journey::Scanner
- Rack

No matching classes.

# Journey::Path::Pattern

### Attributes

anchored[R]
requirements[R]
spec[R]

### Public Class Methods

new(strexp) click to toggle source

    # File lib/journey/path/pattern.rb, line 6
    def initialize strexp
      parser = Journey::Parser.new

      @anchored = true

      case strexp
      when String
        @spec         = parser.parse strexp
        @requirements = {}
        @separators   = "/.?"
      when Router::Strexp
        @spec         = parser.parse strexp.path
        @requirements = strexp.requirements
        @separators   = strexp.separators.join
        @anchored     = strexp.anchor
      else
        raise "wtf bro: #{strexp}"
      end

      @names          = nil
      @optional_names = nil
      @required_names = nil
      @re             = nil
      @offsets        = nil
    end

### Public Instance Methods

=~(other) click to toggle source
Alias for: match
ast() click to toggle source

    # File lib/journey/path/pattern.rb, line 32
    def ast
      @spec.grep(Nodes::Symbol).each do |node|
        re = @requirements[node.to_sym]
        node.regexp = re if re
      end

      @spec.grep(Nodes::Star).each do |node|
        node = node.left
        node.regexp = @requirements[node.to_sym] || /(.+)/
      end

      @spec
    end

match(other) click to toggle source

    # File lib/journey/path/pattern.rb, line 166
    def match other
      return unless match = to_regexp.match(other)
      MatchData.new names, offsets, match
    end

Also aliased as: =~
names() click to toggle source

    # File lib/journey/path/pattern.rb, line 46
    def names
      @names ||= spec.grep(Nodes::Symbol).map { |n| n.name }
    end

optional_names() click to toggle source

    # File lib/journey/path/pattern.rb, line 54
    def optional_names
      @optional_names ||= spec.grep(Nodes::Group).map { |group|
        group.grep(Nodes::Symbol)
      }.flatten.map { |n| n.name }.uniq
    end

required_names() click to toggle source

    # File lib/journey/path/pattern.rb, line 50
    def required_names
      @required_names ||= names - optional_names
    end

source() click to toggle source

    # File lib/journey/path/pattern.rb, line 172
    def source
      to_regexp.source
    end

to_regexp() click to toggle source

    # File lib/journey/path/pattern.rb, line 176
    def to_regexp
      @re ||= regexp_visitor.new(@separators, @requirements).accept spec
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.