module HandlerLink
Constants
- FORMAT_IMG
Public Class Methods
get_host_link(link)
click to toggle source
gets the url, returns domain
# File lib/handler_link.rb, line 5 def self.get_host_link(link) uri = URI.parse(link) "#{uri.scheme}://#{uri.host}" end
handler_links(array_links, link)
click to toggle source
# File lib/handler_link.rb, line 10 def self.handler_links(array_links, link) array_links.each do |url| if url.include?("(/") uri = get_host_link(link) position = url.index("(") url[position] += uri.to_s end end end
handler_prefix_link(host_link, link)
click to toggle source
adds scheme if this href
# File lib/handler_link.rb, line 22 def self.handler_prefix_link(host_link, link) abort 'expect strings params' unless host_link.is_a?(String) || link.is_a?(String) if link[0] == '/' && link[1] != '/' host_link + link elsif link[0..1] == '//' uri = URI.parse(host_link) "#{uri.scheme}:#{link}" else link end end
remove_global_unless_symbols(array_images_links)
click to toggle source
# File lib/handler_link.rb, line 47 def self.remove_global_unless_symbols(array_images_links) array_images_links.each { |link| link.delete!("(,;'')") } end
remove_unless_link(array_links)
click to toggle source
remove link if link not valid
# File lib/handler_link.rb, line 52 def self.remove_unless_link(array_links) array_links.each_with_index do |link, index| array_links[index] = "" if link[0..3] != "http" index_ending = nil FORMAT_IMG.each do |i| index_ending = i if link.include?(i) end unless index_ending == nil position = link.index(index_ending) array_links[index] = "" if (link[position + index_ending.size] =~ /[a-z]/) end end array_links.delete("") end
remove_unless_symbols(array_images_links)
click to toggle source
# File lib/handler_link.rb, line 35 def self.remove_unless_symbols(array_images_links) array_images_links.each do |image_url| if (image_url[0..3] != "http" || image_url[0..3] != "www.") && image_url.include?("(") position = image_url.index("(") image_url.reverse! position.times { image_url.chop! } image_url.reverse! image_url.delete!("(,;'')") end end end