class Tomograph::Path

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/tomograph/path.rb, line 5
def initialize(path)
  unless path && !path.empty?
    @path = ''
    return
  end
  @path = path
  @path = delete_till_the_end('{&')
  @path = delete_till_the_end('{?')
  @path = cut_off_query_params
  @path = remove_the_slash_at_the_end
end

Public Instance Methods

==(other) click to toggle source
# File lib/tomograph/path.rb, line 34
def ==(other)
  other.instance_of? self.class and other.path == path
end
match(find_path) click to toggle source
# File lib/tomograph/path.rb, line 17
def match(find_path)
  regexp =~ find_path
end
regexp() click to toggle source
# File lib/tomograph/path.rb, line 21
def regexp
  return @regexp if @regexp

  str = Regexp.escape(to_s)
  str = str.gsub(/\\{\w+\\}/, '[^&=\/]+')
  str = "\\A#{str}\\z"
  @regexp = Regexp.new(str)
end
to_s() click to toggle source
# File lib/tomograph/path.rb, line 30
def to_s
  @path
end

Private Instance Methods

cut_off_query_params() click to toggle source
# File lib/tomograph/path.rb, line 55
def cut_off_query_params
  @path.gsub(/\?.*\z/, '')
end
delete_till_the_end(beginning_with) click to toggle source
# File lib/tomograph/path.rb, line 40
def delete_till_the_end(beginning_with)
  path_index = @path.index(beginning_with)
  path_index ||= 0
  path_index -= 1
  @path.slice(0..path_index)
end
remove_the_slash_at_the_end() click to toggle source
# File lib/tomograph/path.rb, line 47
def remove_the_slash_at_the_end
  if @path[-1] == '/'
    @path[0..-2]
  else
    @path
  end
end