Class: Redirect::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/redirect/redirect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catch_url, redirect_url, options = {}) ⇒ Data

Returns a new instance of Data.


30
31
32
33
34
35
# File 'lib/redirect/redirect.rb', line 30

def initialize(catch_url, redirect_url, options = {})
  @catch_url = catch_url
  @redirect_url = redirect_url
  @code = options[:code] || Redirect.default_code
  @name = options[:name]
end

Instance Attribute Details

#catch_urlObject (readonly)

Returns the value of attribute catch_url


29
30
31
# File 'lib/redirect/redirect.rb', line 29

def catch_url
  @catch_url
end

#codeObject (readonly)

Returns the value of attribute code


29
30
31
# File 'lib/redirect/redirect.rb', line 29

def code
  @code
end

#matchObject (readonly)

Returns the value of attribute match


29
30
31
# File 'lib/redirect/redirect.rb', line 29

def match
  @match
end

#nameObject (readonly)

Returns the value of attribute name


29
30
31
# File 'lib/redirect/redirect.rb', line 29

def name
  @name
end

Instance Method Details

#matches?(url) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
40
41
# File 'lib/redirect/redirect.rb', line 37

def matches?(url)
  matched = url.match(catch_url)
  @match = $1
  matched
end

#redirect_urlObject


43
44
45
46
47
48
49
# File 'lib/redirect/redirect.rb', line 43

def redirect_url
  if @match
    @redirect_url.gsub('$1', @match)
  else
    @redirect_url
  end
end