Sha256: 903feb96aa8859ce5b04e47f7250dca259c6e374a24c1da6a7f38f4de97d7b51

Contents?: true

Size: 962 Bytes

Versions: 24

Compression:

Stored size: 962 Bytes

Contents

class HttpRouter
  class OptionalCompiler
    attr_reader :paths
    def initialize(path)
      @start_index = 0
      @end_index = 1
      @paths = [""]
      @chars = path.split('')
      while !@chars.empty?
        case @chars.first
          when '('  then @chars.shift and double_paths
          when ')'  then @chars.shift and half_paths
          when '\\' then @chars.shift and add_to_current_set(@chars.shift)
          else           add_to_current_set(@chars.shift)
        end
      end
      @paths
    end
    
    def add_to_current_set(c)
      (@start_index...@end_index).each { |path_index| @paths[path_index] << c }
    end
    
    # over current working set, double @paths
    def double_paths 
      (@start_index...@end_index).each { |path_index| @paths << @paths[path_index].dup }
      @start_index = @end_index
      @end_index = @paths.size
    end

    def half_paths
      @start_index -= @end_index - @start_index
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
http_router-0.4.1 lib/http_router/optional_compiler.rb
http_router-0.4.0 lib/http_router/optional_compiler.rb
http_router-0.3.17 lib/http_router/optional_compiler.rb
http_router-0.3.16 lib/http_router/optional_compiler.rb
http_router-0.3.15 lib/http_router/optional_compiler.rb
http_router-0.3.14 lib/http_router/optional_compiler.rb
http_router-0.3.13 lib/http_router/optional_compiler.rb
http_router-0.3.12 lib/http_router/optional_compiler.rb
http_router-0.3.11 lib/http_router/optional_compiler.rb
http_router-0.3.10 lib/http_router/optional_compiler.rb
http_router-0.3.9 lib/http_router/optional_compiler.rb
http_router-0.3.8 lib/http_router/optional_compiler.rb
http_router-0.3.7 lib/http_router/optional_compiler.rb
http_router-0.3.6 lib/http_router/optional_compiler.rb
http_router-0.3.5 lib/http_router/optional_compiler.rb
http_router-0.3.4 lib/http_router/optional_compiler.rb
http_router-0.3.3 lib/http_router/optional_compiler.rb
http_router-0.3.2 lib/http_router/optional_compiler.rb
http_router-0.3.1 lib/http_router/optional_compiler.rb
http_router-0.3.0 lib/http_router/optional_compiler.rb