Module: DisavowTool::DomainAndUrl
- Included in:
- DisavowList, WhiteList
- Defined in:
- lib/disavow_tool/domain_and_url.rb
Instance Attribute Summary collapse
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#links ⇒ Object
Returns the value of attribute links.
Instance Method Summary collapse
- #add_domain(domain) ⇒ Object
- #add_domain_from_url(url) ⇒ Object
- #add_domain_prefix ⇒ Object
- #add_url(url, list = nil) ⇒ Object
- #clean_line!(line) ⇒ Object
- #domain_or_url(line) ⇒ Object
- #export_write(file) ⇒ Object
- #finished_import_hook ⇒ Object
- #initialize(import_files) ⇒ Object
- #is_url?(link) ⇒ Boolean
- #remove_domain_prefix(domain) ⇒ Object
- #remove_domain_prefix!(domain) ⇒ Object
- #summary ⇒ Object
- #total_elements ⇒ Object
Instance Attribute Details
#domains ⇒ Object
Returns the value of attribute domains.
3 4 5 |
# File 'lib/disavow_tool/domain_and_url.rb', line 3 def domains @domains end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/disavow_tool/domain_and_url.rb', line 3 def links @links end |
Instance Method Details
#add_domain(domain) ⇒ Object
26 27 28 |
# File 'lib/disavow_tool/domain_and_url.rb', line 26 def add_domain(domain) super(domain, @domains) end |
#add_domain_from_url(url) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/disavow_tool/domain_and_url.rb', line 34 def add_domain_from_url(url) domain = URI.parse(URI.escape(url)).host add_domain(domain) p domain return domain end |
#add_domain_prefix ⇒ Object
84 85 86 |
# File 'lib/disavow_tool/domain_and_url.rb', line 84 def add_domain_prefix @domains.collect!{|domain| domain="domain:" + domain} end |
#add_url(url, list = nil) ⇒ Object
30 31 32 |
# File 'lib/disavow_tool/domain_and_url.rb', line 30 def add_url(url, list=nil) super(url, @links) end |
#clean_line!(line) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/disavow_tool/domain_and_url.rb', line 12 def clean_line!(line) case domain_or_url(line) when :domain @domains << remove_domain_prefix(line) when :url @links << line end end |
#domain_or_url(line) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/disavow_tool/domain_and_url.rb', line 59 def domain_or_url(line) if( /^domain/.match(line)) return :domain elsif( /^http/.match(line) ) return :url else raise "Error parsing Disavow file" end end |
#export_write(file) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/disavow_tool/domain_and_url.rb', line 41 def export_write(file) file.puts "# Domains" add_domain_prefix file.puts @domains.to_a puts "Writing #{@domains.count} domains".blue if @verbose file.puts "# urls" file.puts @links.to_a puts "Writing #{@links.count} URLS".blue if @verbose end |
#finished_import_hook ⇒ Object
21 22 23 24 |
# File 'lib/disavow_tool/domain_and_url.rb', line 21 def finished_import_hook @original_domains = @domains.clone @original_links = @links.clone end |
#initialize(import_files) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/disavow_tool/domain_and_url.rb', line 5 def initialize(import_files) @domains = Set.new @links = Set.new p "DomainAndUrl" super(import_files) end |
#is_url?(link) ⇒ Boolean
69 70 71 72 73 74 75 |
# File 'lib/disavow_tool/domain_and_url.rb', line 69 def is_url?(link) unless( link.match(/^http(s)?\:/) ) :domain else :url end end |
#remove_domain_prefix(domain) ⇒ Object
77 78 79 |
# File 'lib/disavow_tool/domain_and_url.rb', line 77 def remove_domain_prefix(domain) domain.gsub(/^domain\:/, '') end |
#remove_domain_prefix!(domain) ⇒ Object
80 81 82 |
# File 'lib/disavow_tool/domain_and_url.rb', line 80 def remove_domain_prefix!(domain) domain.gsub!(/^domain\:/, '') end |
#summary ⇒ Object
51 52 53 54 55 56 |
# File 'lib/disavow_tool/domain_and_url.rb', line 51 def summary puts .green super(@links, @original_links) puts .green super(@domains, @original_domains) end |
#total_elements ⇒ Object
88 89 90 |
# File 'lib/disavow_tool/domain_and_url.rb', line 88 def total_elements @domains.count + @links.count end |