Module: HandlerLink

Defined in:
lib/handler_link.rb

Constant Summary collapse

FORMAT_IMG =
["jpg", "jpeg", "png", "gif"]

Class Method Summary collapse

Class Method Details

gets the url, returns domain



5
6
7
8
# File 'lib/handler_link.rb', line 5

def self.get_host_link(link)
  uri = URI.parse(link)
  "#{uri.scheme}://#{uri.host}"
end


10
11
12
13
14
15
16
17
18
19
# 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

adds scheme if this href



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



47
48
49
# 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 link if link not valid



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# 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