class ActionDispatch::Journey::Format - actionpack-4.2.3 Documentation

# class ActionDispatch::Journey::Format

### Constants

ESCAPE_PATH
ESCAPE_SEGMENT

### Public Class Methods

new(parts) click to toggle source

    # File lib/action_dispatch/journey/visitors.rb, line 20
    def initialize(parts)
      @parts      = parts
      @children   = []
      @parameters = []

      parts.each_with_index do |object,i|
        case object
        when Journey::Format
          @children << i
        when Parameter
          @parameters << i
        end
      end
    end

required_path(symbol) click to toggle source

    # File lib/action_dispatch/journey/visitors.rb, line 12
    def self.required_path(symbol)
      Parameter.new symbol, ESCAPE_PATH
    end

required_segment(symbol) click to toggle source

    # File lib/action_dispatch/journey/visitors.rb, line 16
    def self.required_segment(symbol)
      Parameter.new symbol, ESCAPE_SEGMENT
    end

### Public Instance Methods

evaluate(hash) click to toggle source

    # File lib/action_dispatch/journey/visitors.rb, line 35
    def evaluate(hash)
      parts = @parts.dup

      @parameters.each do |index|
        param = parts[index]
        value = hash[param.name]
        return ''.freeze unless value
        parts[index] = param.escape value
      end

      @children.each { |index| parts[index] = parts[index].evaluate(hash) }

      parts.join
    end