Class: VanityUrlPage

Inherits:
Page
  • Object
show all
Defined in:
app/models/vanity_url_page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean_comparison_path(path) ⇒ Object



18
19
20
# File 'app/models/vanity_url_page.rb', line 18

def clean_comparison_path(path)
  "#{clean_path(path)}/"
end

.clean_path(path) ⇒ Object



22
23
24
# File 'app/models/vanity_url_page.rb', line 22

def clean_path(path)
  "/#{path.to_s.strip}".gsub(%r{//+}, '/')
end

.find_vanity_url_by_path(path, live = true) ⇒ Object



9
10
11
12
13
14
15
16
# File 'app/models/vanity_url_page.rb', line 9

def find_vanity_url_by_path(path, live = true)
  vanity_url_page = Page.current_site.homepage.children.find_by_slug('vanity-urls')
  vanity_pages = vanity_url_page.children.where("vanity_url like '%#{path}%'")
  vanity_pages.each do |vanity_page|
    return vanity_page if clean_comparison_path(path).downcase == clean_comparison_path(vanity_page.vanity_url).downcase
  end
  nil
end

Instance Method Details

#clean_target_urlObject



3
4
5
# File 'app/models/vanity_url_page.rb', line 3

def clean_target_url
  (self.target_url.match('http://') || self.target_url.match('https://')) ? self.target_url : VanityUrlPage.clean_path(self.target_url)
end